Unverified Commit 64ef34ec authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Revert "Remove extra suspense boundary for default next/dynamic" (#65309)

Reverting temporarily while we investigate a bug where the page crashes
due to the missing `Suspense`.

x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1714691721631339)

Reverts vercel/next.js#64716

Closes NEXT-3307
parent 025f5b6b
...@@ -41,7 +41,6 @@ export type DynamicOptions<P = {}> = LoadableGeneratedOptions & { ...@@ -41,7 +41,6 @@ export type DynamicOptions<P = {}> = LoadableGeneratedOptions & {
loadableGenerated?: LoadableGeneratedOptions loadableGenerated?: LoadableGeneratedOptions
ssr?: boolean ssr?: boolean
/** /**
* TODO: remove this in next major version v15
* @deprecated `suspense` prop is not required anymore * @deprecated `suspense` prop is not required anymore
*/ */
suspense?: boolean suspense?: boolean
......
import { Suspense, Fragment, lazy } from 'react' import { Suspense, lazy } from 'react'
import { BailoutToCSR } from './dynamic-bailout-to-csr' import { BailoutToCSR } from './dynamic-bailout-to-csr'
import type { ComponentModule } from './types' import type { ComponentModule } from './types'
import { PreloadCss } from './preload-css' import { PreloadCss } from './preload-css'
...@@ -48,10 +48,7 @@ function Loadable(options: LoadableOptions) { ...@@ -48,10 +48,7 @@ function Loadable(options: LoadableOptions) {
<Loading isLoading={true} pastDelay={true} error={null} /> <Loading isLoading={true} pastDelay={true} error={null} />
) : null ) : null
const isSSR = opts.ssr const children = opts.ssr ? (
const Wrap = isSSR ? Fragment : Suspense
const wrapProps = isSSR ? {} : { fallback: fallbackElement }
const children = isSSR ? (
<> <>
{/* During SSR, we need to preload the CSS from the dynamic component to avoid flash of unstyled content */} {/* During SSR, we need to preload the CSS from the dynamic component to avoid flash of unstyled content */}
{typeof window === 'undefined' ? ( {typeof window === 'undefined' ? (
...@@ -65,7 +62,7 @@ function Loadable(options: LoadableOptions) { ...@@ -65,7 +62,7 @@ function Loadable(options: LoadableOptions) {
</BailoutToCSR> </BailoutToCSR>
) )
return <Wrap {...wrapProps}>{children}</Wrap> return <Suspense fallback={fallbackElement}>{children}</Suspense>
} }
LoadableComponent.displayName = 'LoadableComponent' LoadableComponent.displayName = 'LoadableComponent'
......
const isDevTest = false
const DynamicImportComponent = () => {
if (isDevTest && typeof window === 'undefined') {
throw new Error('This component should only be rendered on the client side')
}
return (
<div id="dynamic-component">This is a dynamically imported component</div>
)
}
export default DynamicImportComponent
'use client'
import dynamic from 'next/dynamic'
const DynamicHeader = dynamic(() => import('./dynamic-component'), {
loading: () => <p>Loading...</p>,
})
const ClientWrapper = () => {
return (
<div>
<DynamicHeader />
</div>
)
}
export default ClientWrapper
import { nextTestSetup } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app dir - next/dynamic', () => { describe('app dir - next/dynamic', () => {
const { next, isNextStart, isNextDev, skipped } = nextTestSetup({ const { next, isNextStart, skipped } = nextTestSetup({
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
}) })
...@@ -58,26 +57,6 @@ describe('app dir - next/dynamic', () => { ...@@ -58,26 +57,6 @@ describe('app dir - next/dynamic', () => {
expect($('h1').text()).toBe('hello') expect($('h1').text()).toBe('hello')
}) })
it('should not render loading by default', async () => {
const $ = await next.render$('/default')
expect($('#dynamic-component').text()).not.toContain('loading')
})
if (isNextDev) {
it('should directly raise error when dynamic component error on server', async () => {
const pagePath = 'app/default/dynamic-component.js'
const page = await next.readFile(pagePath)
await next.patchFile(
pagePath,
page.replace('const isDevTest = false', 'const isDevTest = true')
)
await retry(async () => {
const { status } = await next.fetch('/default')
expect(status).toBe(500)
})
})
}
describe('no SSR', () => { describe('no SSR', () => {
it('should not render client component imported through ssr: false in client components in edge runtime', async () => { it('should not render client component imported through ssr: false in client components in edge runtime', async () => {
// noSSR should not show up in html // noSSR should not show up in html
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment