@@ -2,7 +2,6 @@ import React, { HTMLAttributes, useEffect, useContext, useState, useMemo, useRef
2
2
import Layout from '../components/Layout' ;
3
3
import { graphql } from 'gatsby' ;
4
4
import RehypeReact from 'rehype-react' ;
5
- import { InteractiveCodeBlock } from '../components/InteractiveCodeBlock/InteractiveCodeBlock' ;
6
5
import { CacheableLineTokens , TypeScriptTokenType } from '../components/InteractiveCodeBlock/tokenizers/types' ;
7
6
import { useProgressiveTokenizer , ComposedTokenT } from '../hooks' ;
8
7
import { useDeferredRender } from '../hooks/useDeferredRender' ;
@@ -109,57 +108,60 @@ function ProgressiveCodeBlock(props: { children: [React.ReactElement<HTMLAttribu
109
108
fileName,
110
109
visibleSpan : span ,
111
110
} ) ;
112
- const deferredCodeBlock = useDeferredRender ( ( ) => (
113
- < InteractiveCodeBlock
114
- className = "tm-theme"
115
- initialValue = { originalText }
116
- tokenizer = { tokenizer }
117
- readOnly = { ! isInitialized }
118
- onStartEditing = { ( ) => {
119
- setShouldInitialize ( true ) ;
120
- onStartEditing ! ( fileName ) ;
121
- } }
122
- isLoading = { isLoading }
123
- onChange = { value => {
124
- const start = getStartOfCodeBlock ( id , mutableCodeBlocks , sourceFiles ! [ codeBlock . fileName ] ) ;
125
- const end = start + value . length ;
126
- const newSpan = { start, length : value . length } ;
127
- mutableCodeBlocks [ id ] . end = end ;
128
- if ( tsEnv && mutableCodeBlocks [ id ] . text !== value ) {
129
- mutableCodeBlocks [ id ] . text = value ;
130
- tsEnv . updateFile ( fileName , value , span ) ;
131
- }
132
- setSpan ( newSpan ) ;
133
- } }
134
- renderToken = { ( token , tokenProps ) => {
135
- switch ( token . type ) {
136
- case 'tm' :
137
- return (
138
- < span
139
- className = { token . scopes . reduce ( ( scopes , s ) => `${ scopes } ${ s . split ( '.' ) . join ( ' ' ) } ` , '' ) }
140
- { ...tokenProps }
141
- />
142
- ) ;
143
- case TypeScriptTokenType . Identifier :
144
- return (
145
- < TypeScriptIdentifierToken
146
- staticQuickInfo = { quickInfo }
147
- languageService = { tsEnv && isInitialized && tsEnv . languageService }
148
- sourceFileName = { fileName }
149
- position = { token . sourcePosition }
150
- { ...tokenProps }
151
- />
152
- ) ;
153
- case TypeScriptTokenType . Diagnostic :
154
- return (
155
- < TypeScriptDiagnosticToken message = { token . diagnosticMessage } { ...tokenProps } />
156
- ) ;
157
- default :
158
- return < span { ...tokenProps } /> ;
159
- }
160
- } }
161
- />
162
- ) , { timeout : 1000 } ) ;
111
+ const deferredCodeBlock = useDeferredRender ( async ( ) => {
112
+ const { InteractiveCodeBlock } = await import ( '../components/InteractiveCodeBlock/InteractiveCodeBlock' ) ;
113
+ return (
114
+ < InteractiveCodeBlock
115
+ className = "tm-theme"
116
+ initialValue = { originalText }
117
+ tokenizer = { tokenizer }
118
+ readOnly = { ! isInitialized }
119
+ onStartEditing = { ( ) => {
120
+ setShouldInitialize ( true ) ;
121
+ onStartEditing ! ( fileName ) ;
122
+ } }
123
+ isLoading = { isLoading }
124
+ onChange = { value => {
125
+ const start = getStartOfCodeBlock ( id , mutableCodeBlocks , sourceFiles ! [ codeBlock . fileName ] ) ;
126
+ const end = start + value . length ;
127
+ const newSpan = { start, length : value . length } ;
128
+ mutableCodeBlocks [ id ] . end = end ;
129
+ if ( tsEnv && mutableCodeBlocks [ id ] . text !== value ) {
130
+ mutableCodeBlocks [ id ] . text = value ;
131
+ tsEnv . updateFile ( fileName , value , span ) ;
132
+ }
133
+ setSpan ( newSpan ) ;
134
+ } }
135
+ renderToken = { ( token , tokenProps ) => {
136
+ switch ( token . type ) {
137
+ case 'tm' :
138
+ return (
139
+ < span
140
+ className = { token . scopes . reduce ( ( scopes , s ) => `${ scopes } ${ s . split ( '.' ) . join ( ' ' ) } ` , '' ) }
141
+ { ...tokenProps }
142
+ />
143
+ ) ;
144
+ case TypeScriptTokenType . Identifier :
145
+ return (
146
+ < TypeScriptIdentifierToken
147
+ staticQuickInfo = { quickInfo }
148
+ languageService = { tsEnv && isInitialized && tsEnv . languageService }
149
+ sourceFileName = { fileName }
150
+ position = { token . sourcePosition }
151
+ { ...tokenProps }
152
+ />
153
+ ) ;
154
+ case TypeScriptTokenType . Diagnostic :
155
+ return (
156
+ < TypeScriptDiagnosticToken message = { token . diagnosticMessage } { ...tokenProps } />
157
+ ) ;
158
+ default :
159
+ return < span { ...tokenProps } /> ;
160
+ }
161
+ } }
162
+ />
163
+ ) ;
164
+ } , { timeout : 1000 } ) ;
163
165
164
166
return (
165
167
< ErrorCatcher renderFallback = { ( ) => < CheapCodeBlock > { text } </ CheapCodeBlock > } >
0 commit comments