-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: regression in pages router on
next/dynamic
imports
- Loading branch information
Showing
2 changed files
with
24 additions
and
12 deletions.
There are no files selected for viewing
18 changes: 12 additions & 6 deletions
18
packages/next-sanity/src/studio/client-component/NextStudioLazy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
/** | ||
* This file works around a new restriction in Next v15 where server components are not allowed | ||
* to use dynamic(() => import('...), {ssr: false}) | ||
* only Client Components can set ssr: false. | ||
* | ||
* If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`), | ||
* or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet) | ||
* we could use `dynamic(() => import('...), {ssr: false})` here. | ||
* Since we can't, we need to use a lazy import and Suspense ourself. | ||
*/ | ||
|
||
import dynamic from 'next/dynamic' | ||
import {lazy, Suspense} from 'react' | ||
|
||
import type {NextStudioProps} from './NextStudio' | ||
|
||
const NextStudioClientComponent = dynamic(() => import('./NextStudio'), {ssr: false}) | ||
const NextStudioClientComponent = lazy(() => import('./NextStudio')) | ||
|
||
export function NextStudioLazyClientComponent(props: NextStudioProps): React.ReactNode { | ||
return <NextStudioClientComponent {...props} /> | ||
return ( | ||
<Suspense fallback={null}> | ||
<NextStudioClientComponent {...props} /> | ||
</Suspense> | ||
) | ||
} |
18 changes: 12 additions & 6 deletions
18
packages/next-sanity/src/visual-editing/client-component/VisualEditingLazy.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
/** | ||
* This file works around a new restriction in Next v15 where server components are not allowed | ||
* to use dynamic(() => import('...), {ssr: false}) | ||
* only Client Components can set ssr: false. | ||
* | ||
* If pages router supported `next/dynamic` imports (it wants `next/dynamic.js`), | ||
* or if turbopack in app router allowed `next/dynamic.js` (it doesn't yet) | ||
* we could use `dynamic(() => import('...), {ssr: false})` here. | ||
* Since we can't, we need to use a lazy import and Suspense ourself. | ||
*/ | ||
|
||
import dynamic from 'next/dynamic' | ||
import {lazy, Suspense} from 'react' | ||
|
||
import type {VisualEditingProps} from './VisualEditing' | ||
|
||
const VisualEditingClientComponent = dynamic(() => import('./VisualEditing'), {ssr: false}) | ||
const VisualEditingClientComponent = lazy(() => import('./VisualEditing')) | ||
|
||
export function VisualEditingLazyClientComponent(props: VisualEditingProps): React.ReactNode { | ||
return <VisualEditingClientComponent {...props} /> | ||
return ( | ||
<Suspense fallback={null}> | ||
<VisualEditingClientComponent {...props} /> | ||
</Suspense> | ||
) | ||
} |