@@ -9,39 +9,42 @@ import { CodeA, CodeB, CodeC } from "@/components/code-blocks"
9
9
import { HowItWorksListItem } from "./how-it-works-list-item"
10
10
import { PlayButton } from "./play-button"
11
11
12
- const InteractiveEditor = dynamic ( import ( "./interactive-editor" ) , {
12
+ const InteractiveEditor = dynamic ( ( ) => import ( "./interactive-editor" ) , {
13
13
ssr : false ,
14
14
} )
15
15
16
16
const TRY_IT_OUT_URL = "https://graphql.org/swapi-graphql"
17
17
18
18
export function HowItWorks ( ) {
19
19
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
20
22
const inView = useInView ( sectionRef )
21
23
22
24
return (
23
25
< section ref = { sectionRef } className = "gql-container gql-section xl:py-20" >
24
26
< SectionLabel className = "mb-6" > How it works</ SectionLabel >
25
27
< 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 >
43
46
) }
44
- </ ol >
47
+ </ div >
45
48
46
49
< Button className = "mx-auto mt-8 w-fit lg:mt-16" href = { TRY_IT_OUT_URL } >
47
50
Try GraphiQL
0 commit comments