Skip to content

Commit 41a2eb2

Browse files
authored
Clean up legacy react 18 tests (#35615)
### source changes * Error dynamic suspense option in non concurrent mode, don't check react root anymore since they should be bound ### tests changes * Remove duplicated rsc client test * Merge type checking cases (`next/dynamic`) * Remove blocking rendering tests cases since we should opt-in Fizz rendering when using React.lazy * Remove some thrown promises cases, leverage the streaming component we had in RSC test
1 parent 4bfcf83 commit 41a2eb2

31 files changed

Lines changed: 95 additions & 444 deletions

File tree

packages/next/shared/lib/dynamic.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,11 @@ export default function dynamic<P = {}>(
117117
const suspenseOptions = loadableOptions as LoadableSuspenseOptions & {
118118
loader: Loader<P>
119119
}
120-
if (!process.env.__NEXT_CONCURRENT_FEATURES) {
121-
// Error if react root is not enabled and `suspense` option is set to true
122-
if (!process.env.__NEXT_REACT_ROOT && suspenseOptions.suspense) {
123-
// TODO: add error doc when this feature is stable
124-
throw new Error(
125-
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
126-
)
127-
}
120+
// Error if Fizz rendering is not enabled and `suspense` option is set to true
121+
if (!process.env.__NEXT_CONCURRENT_FEATURES && suspenseOptions.suspense) {
122+
throw new Error(
123+
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
124+
)
128125
}
129126
if (suspenseOptions.suspense) {
130127
return loadableFn(suspenseOptions)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default () => 'foo'

test/integration/react-18-invalid-config/index.test.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { File, nextBuild } from 'next-test-utils'
66

77
const appDir = __dirname
88
const nextConfig = new File(join(appDir, 'next.config.js'))
9+
const reactDomPackagePah = join(appDir, 'node_modules/react-dom')
910

1011
function writeNextConfig(config) {
1112
const content = `module.exports = { experimental: ${JSON.stringify(config)} }`
@@ -24,21 +25,36 @@ describe('Invalid react 18 webpack config', () => {
2425
'`experimental.runtime` requires `experimental.reactRoot` to be enabled along with React 18.'
2526
)
2627
})
28+
})
2729

28-
it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
29-
const reactDomPackagePah = join(appDir, 'node_modules/react-dom')
30+
describe('React 17 with React 18 config', () => {
31+
beforeAll(async () => {
3032
await fs.mkdirp(reactDomPackagePah)
3133
await fs.writeFile(
3234
join(reactDomPackagePah, 'package.json'),
3335
JSON.stringify({ name: 'react-dom', version: '17.0.0' })
3436
)
3537
writeNextConfig({ reactRoot: true })
36-
const { stderr } = await nextBuild(appDir, [], { stderr: true })
38+
})
39+
afterAll(async () => {
3740
await fs.remove(reactDomPackagePah)
3841
nextConfig.restore()
42+
})
3943

44+
it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
45+
const { stderr } = await nextBuild(appDir, [], { stderr: true })
4046
expect(stderr).toContain(
4147
'You have to use React 18 to use `experimental.reactRoot`.'
4248
)
4349
})
50+
51+
it('suspense is not allowed in blocking rendering mode', async () => {
52+
const { stderr, code } = await nextBuild(appDir, [], {
53+
stderr: true,
54+
})
55+
expect(stderr).toContain(
56+
'Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense'
57+
)
58+
expect(code).toBe(1)
59+
})
4460
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React, { Suspense } from 'react'
2+
import dynamic from 'next/dynamic'
3+
4+
const Foo = dynamic(() => import('../components/foo'), { suspense: true })
5+
6+
export default function Dynamic() {
7+
return (
8+
<Suspense>
9+
<Foo />
10+
</Suspense>
11+
)
12+
}

test/integration/react-18/app/components/bar.js

Lines changed: 0 additions & 24 deletions
This file was deleted.

test/integration/react-18/app/components/dynamic-hello.js

Lines changed: 0 additions & 18 deletions
This file was deleted.

test/integration/react-18/app/components/foo.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/integration/react-18/app/components/hello.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/integration/react-18/app/components/promise-cache.js

Lines changed: 0 additions & 37 deletions
This file was deleted.

test/integration/react-18/app/components/red.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)