1+ /*
2+ * Copyright (c) Facebook, Inc. and its affiliates.
3+ */
4+
15import * as React from 'react' ;
2- import { reducedCodeSnippet } from './utils' ;
3- const Sandpack = React . lazy ( ( ) => import ( './SandpackWrapper' ) ) ;
6+ import dynamic from 'next/dynamic' ;
7+ import { createFileMap } from './utils' ;
8+
9+ const SandpackRoot = dynamic ( ( ) => import ( './SandpackRoot' ) , { suspense : true } ) ;
410
5- const SandpackFallBack = ( { code} : { code : string } ) => (
11+ const SandpackGlimmer = ( { code} : { code : string } ) => (
612 < div className = "sandpack-container my-8" >
713 < div className = "shadow-lg dark:shadow-lg-dark rounded-lg" >
814 < div className = "bg-wash h-10 dark:bg-card-dark flex justify-between items-center relative z-10 border-b border-border dark:border-border-dark rounded-t-lg rounded-b-none" >
@@ -41,11 +47,10 @@ const SandpackFallBack = ({code}: {code: string}) => (
4147) ;
4248
4349export default React . memo ( function SandpackWrapper ( props : any ) : any {
44- const codeSnippet = reducedCodeSnippet (
45- React . Children . toArray ( props . children )
46- ) ;
50+ const codeSnippet = createFileMap ( React . Children . toArray ( props . children ) ) ;
4751
48- // To set the active file in the fallback we have to find the active file first. If there are no active files we fallback to App.js as default
52+ // To set the active file in the fallback we have to find the active file first.
53+ // If there are no active files we fallback to App.js as default.
4954 let activeCodeSnippet = Object . keys ( codeSnippet ) . filter (
5055 ( fileName ) =>
5156 codeSnippet [ fileName ] ?. active === true &&
@@ -59,10 +64,8 @@ export default React.memo(function SandpackWrapper(props: any): any {
5964 }
6065
6166 return (
62- < >
63- < React . Suspense fallback = { < SandpackFallBack code = { activeCode } /> } >
64- < Sandpack { ...props } />
65- </ React . Suspense >
66- </ >
67+ < React . Suspense fallback = { < SandpackGlimmer code = { activeCode } /> } >
68+ < SandpackRoot { ...props } />
69+ </ React . Suspense >
6770 ) ;
6871} ) ;
0 commit comments