Skip to content

Commit af69f2f

Browse files
committed
Wrap dynamic import in a thunk (-.-)
1 parent 0db7923 commit af69f2f

File tree

1 file changed

+22
-19
lines changed
  • src/components/index-page/how-it-works

1 file changed

+22
-19
lines changed

src/components/index-page/how-it-works/index.tsx

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,42 @@ import { CodeA, CodeB, CodeC } from "@/components/code-blocks"
99
import { HowItWorksListItem } from "./how-it-works-list-item"
1010
import { PlayButton } from "./play-button"
1111

12-
const InteractiveEditor = dynamic(import("./interactive-editor"), {
12+
const InteractiveEditor = dynamic(() => import("./interactive-editor"), {
1313
ssr: false,
1414
})
1515

1616
const TRY_IT_OUT_URL = "https://graphql.org/swapi-graphql"
1717

1818
export function HowItWorks() {
1919
const sectionRef = useRef<HTMLElement>(null)
20+
// todo: we could technically consider loading the chunk on hover or focus,
21+
// just so people scrolling through the page don't download CodeMirror
2022
const inView = useInView(sectionRef)
2123

2224
return (
2325
<section ref={sectionRef} className="gql-container gql-section xl:py-20">
2426
<SectionLabel className="mb-6">How it works</SectionLabel>
2527
<h2 className="typography-h2 mb-6 lg:mb-16">A GraphQL Query</h2>
26-
<ol className="gql-radial-gradient list-none gap-px max-md:bg-gradient-to-r max-md:from-transparent max-md:via-neu-400 max-md:to-transparent lg:grid lg:grid-cols-3">
27-
<HowItWorksListItem text="Describe your data" code={<CodeA />} />
28-
{/* TODO: There's a blink on transition sometimes. We need to mount the new editor before unmounting the old one. */}
29-
{inView ? (
30-
<InteractiveEditor />
31-
) : (
32-
<>
33-
<HowItWorksListItem
34-
text="Ask for what you want"
35-
icon={<PlayButton />}
36-
code={<CodeB />}
37-
/>
38-
<HowItWorksListItem
39-
text="Get predictable results"
40-
code={<CodeC />}
41-
/>
42-
</>
28+
<div className="relative">
29+
<ol className="gql-radial-gradient list-none gap-px max-md:bg-gradient-to-r max-md:from-transparent max-md:via-neu-400 max-md:to-transparent lg:grid lg:grid-cols-3">
30+
<HowItWorksListItem text="Describe your data" code={<CodeA />} />
31+
<HowItWorksListItem
32+
text="Ask for what you want"
33+
icon={<PlayButton />}
34+
code={<CodeB />}
35+
/>
36+
<HowItWorksListItem text="Get predictable results" code={<CodeC />} />
37+
</ol>
38+
{inView && (
39+
<ol
40+
// this is rendered *on top* of the static version to avoid layout shift
41+
className="absolute inset-0 list-none gap-px lg:grid lg:grid-cols-3"
42+
>
43+
<div className="pointer-events-none" />
44+
<InteractiveEditor />
45+
</ol>
4346
)}
44-
</ol>
47+
</div>
4548

4649
<Button className="mx-auto mt-8 w-fit lg:mt-16" href={TRY_IT_OUT_URL}>
4750
Try GraphiQL

0 commit comments

Comments
 (0)