Skip to content

Commit

Permalink
Error on suspense in blocking rendering mode
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 14, 2021
1 parent c3dcc96 commit 5b12dd5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 101 deletions.
14 changes: 5 additions & 9 deletions packages/next/shared/lib/dynamic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,11 @@ export default function dynamic<P = {}>(
loadableOptions = { ...loadableOptions, ...options }

const suspenseOptions = loadableOptions as LoadableSuspenseOptions<P>
if (!process.env.__NEXT_CONCURRENT_FEATURES) {
// Error if react root is not enabled and `suspense` option is set to true
if (!process.env.__NEXT_REACT_ROOT && suspenseOptions.suspense) {
// TODO: add error doc when this feature is stable
throw new Error(
`Disallowed suspense option usage with next/dynamic in blocking mode`
)
}
suspenseOptions.suspense = false
if (!process.env.__NEXT_CONCURRENT_FEATURES && suspenseOptions.suspense) {
// TODO: add error doc when this feature is stable
throw new Error(
`Disallowed suspense option usage with next/dynamic in blocking mode`
)
}
if (suspenseOptions.suspense) {
return loadableFn(suspenseOptions)
Expand Down
10 changes: 0 additions & 10 deletions test/integration/react-18/app/pages/suspense/unwrapped.js

This file was deleted.

31 changes: 0 additions & 31 deletions test/integration/react-18/test/basics.js

This file was deleted.

27 changes: 0 additions & 27 deletions test/integration/react-18/test/blocking.js

This file was deleted.

28 changes: 4 additions & 24 deletions test/integration/react-18/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ import {
nextStart,
renderViaHTTP,
} from 'next-test-utils'
import blocking from './blocking'
import concurrent from './concurrent'
import basics from './basics'

jest.setTimeout(1000 * 60 * 5)

Expand Down Expand Up @@ -80,14 +78,6 @@ describe('React 18 Support', () => {
expect(output).not.toMatch(USING_CREATE_ROOT)
expect(output).not.toMatch(UNSUPPORTED_PRERELEASE)
})

it('suspense is not allowed in blocking rendering mode', async () => {
const appPort = await findPort()
const app = await launchApp(appDir, appPort)
const html = await renderViaHTTP(appPort, '/suspense/unwrapped')
await killApp(app)
expect(html).toContain(SUSPENSE_ERROR_MESSAGE)
})
})

describe('warns with stable supported version of react-dom', () => {
Expand Down Expand Up @@ -117,13 +107,6 @@ describe('React 18 Support', () => {
})
})

describe('Basics', () => {
runTests('default setting with react 18', 'dev', (context) => basics(context))
runTests('default setting with react 18', 'prod', (context) =>
basics(context)
)
})

describe('Blocking mode', () => {
beforeAll(() => {
dynamicHello.replace('suspense = false', `suspense = true`)
Expand All @@ -132,13 +115,10 @@ describe('Blocking mode', () => {
dynamicHello.restore()
})

runTests('concurrentFeatures is disabled', 'dev', (context) =>
blocking(context, (p, q) => renderViaHTTP(context.appPort, p, q))
)

runTests('concurrentFeatures is disabled', 'prod', (context) =>
blocking(context, (p, q) => renderViaHTTP(context.appPort, p, q))
)
it('suspense is not allowed in blocking rendering mode (prod)', async () => {
const output = await getBuildOutput(appDir)
expect(output).toContain(SUSPENSE_ERROR_MESSAGE)
})
})

describe('Concurrent mode', () => {
Expand Down

0 comments on commit 5b12dd5

Please sign in to comment.