File tree 1 file changed +21
-11
lines changed
1 file changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -222,24 +222,34 @@ if (unusedBlacklistPatterns.size > 0) {
222
222
) ;
223
223
}
224
224
225
- const viewerRoot = ReactDOMClient . createRoot ( document . getElementById ( 'test-viewer' ) ) ;
225
+ const viewerRoot = document . getElementById ( 'test-viewer' ) ;
226
226
227
227
function FixtureRenderer ( { component : FixtureComponent } ) {
228
+ const viewerReactRoot = React . useRef ( null ) ;
229
+
228
230
React . useLayoutEffect ( ( ) => {
229
- const children = (
230
- < TestViewer >
231
- < FixtureComponent />
232
- </ TestViewer >
233
- ) ;
231
+ const renderTimeout = setTimeout ( ( ) => {
232
+ const children = (
233
+ < TestViewer >
234
+ < FixtureComponent />
235
+ </ TestViewer >
236
+ ) ;
234
237
235
- viewerRoot . render ( children ) ;
236
- } , [ FixtureComponent ] ) ;
238
+ if ( viewerReactRoot . current === null ) {
239
+ viewerReactRoot . current = ReactDOMClient . createRoot ( viewerRoot ) ;
240
+ }
241
+
242
+ viewerReactRoot . current . render ( children ) ;
243
+ } ) ;
237
244
238
- React . useLayoutEffect ( ( ) => {
239
245
return ( ) => {
240
- viewerRoot . unmount ( ) ;
246
+ clearTimeout ( renderTimeout ) ;
247
+ setTimeout ( ( ) => {
248
+ viewerReactRoot . current . unmount ( ) ;
249
+ viewerReactRoot . current = null ;
250
+ } ) ;
241
251
} ;
242
- } , [ ] ) ;
252
+ } , [ FixtureComponent ] ) ;
243
253
244
254
return null ;
245
255
}
You can’t perform that action at this time.
0 commit comments