Skip to content

Commit

Permalink
fix: regression in pages router on next/dynamic imports
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Oct 15, 2024
1 parent 865979c commit 01701b2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
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>
)
}
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>
)
}

0 comments on commit 01701b2

Please sign in to comment.