Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up legacy react 18 tests #35615

Merged
merged 5 commits into from Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 5 additions & 8 deletions packages/next/shared/lib/dynamic.tsx
Expand Up @@ -117,14 +117,11 @@ export default function dynamic<P = {}>(
const suspenseOptions = loadableOptions as LoadableSuspenseOptions & {
loader: Loader<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(
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
)
}
// Error if Fizz rendering is not enabled and `suspense` option is set to true
if (!process.env.__NEXT_CONCURRENT_FEATURES && suspenseOptions.suspense) {
throw new Error(
`Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense`
)
}
if (suspenseOptions.suspense) {
return loadableFn(suspenseOptions)
Expand Down
@@ -0,0 +1 @@
export default () => 'foo'
22 changes: 19 additions & 3 deletions test/integration/react-18-invalid-config/index.test.js
Expand Up @@ -6,6 +6,7 @@ import { File, nextBuild } from 'next-test-utils'

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

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

it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
const reactDomPackagePah = join(appDir, 'node_modules/react-dom')
describe('React 17 with React 18 config', () => {
beforeAll(async () => {
await fs.mkdirp(reactDomPackagePah)
await fs.writeFile(
join(reactDomPackagePah, 'package.json'),
JSON.stringify({ name: 'react-dom', version: '17.0.0' })
)
writeNextConfig({ reactRoot: true })
const { stderr } = await nextBuild(appDir, [], { stderr: true })
})
afterAll(async () => {
await fs.remove(reactDomPackagePah)
nextConfig.restore()
})

it('should warn user when not using react 18 and `experimental.reactRoot` is enabled', async () => {
const { stderr } = await nextBuild(appDir, [], { stderr: true })
expect(stderr).toContain(
'You have to use React 18 to use `experimental.reactRoot`.'
)
})

it('suspense is not allowed in blocking rendering mode', async () => {
const { stderr, code } = await nextBuild(appDir, [], {
stderr: true,
})
expect(stderr).toContain(
'Invalid suspense option usage in next/dynamic. Read more: https://nextjs.org/docs/messages/invalid-dynamic-suspense'
)
expect(code).toBe(1)
})
})
12 changes: 12 additions & 0 deletions test/integration/react-18-invalid-config/pages/dynamic.js
@@ -0,0 +1,12 @@
import React, { Suspense } from 'react'
import dynamic from 'next/dynamic'

const Foo = dynamic(() => import('../components/foo'), { suspense: true })

export default function Dynamic() {
return (
<Suspense>
<Foo />
</Suspense>
)
}
24 changes: 0 additions & 24 deletions test/integration/react-18/app/components/bar.js

This file was deleted.

18 changes: 0 additions & 18 deletions test/integration/react-18/app/components/dynamic-hello.js

This file was deleted.

3 changes: 0 additions & 3 deletions test/integration/react-18/app/components/foo.js

This file was deleted.

37 changes: 0 additions & 37 deletions test/integration/react-18/app/components/hello.js

This file was deleted.

37 changes: 0 additions & 37 deletions test/integration/react-18/app/components/promise-cache.js

This file was deleted.

21 changes: 0 additions & 21 deletions test/integration/react-18/app/components/red.js

This file was deleted.

21 changes: 21 additions & 0 deletions test/integration/react-18/app/components/red.tsx
@@ -0,0 +1,21 @@
import React, { Suspense } from 'react'
import { createStreamingData } from '../../test/streaming-data'

const Data = createStreamingData()

export default function Styled() {
return (
<Suspense fallback={`fallback`}>
<Data>
<div>
<p>This is Red.</p>
<style jsx>{`
p {
color: red;
}
`}</style>
</div>
</Data>
</Suspense>
)
}
3 changes: 0 additions & 3 deletions test/integration/react-18/app/components/ts-foo.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions test/integration/react-18/app/pages/_app.js

This file was deleted.

8 changes: 0 additions & 8 deletions test/integration/react-18/app/pages/ssr.js

This file was deleted.

28 changes: 0 additions & 28 deletions test/integration/react-18/app/pages/suspense/backpressure.js

This file was deleted.

22 changes: 0 additions & 22 deletions test/integration/react-18/app/pages/suspense/no-preload.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/integration/react-18/app/pages/suspense/no-thrown.js

This file was deleted.

5 changes: 0 additions & 5 deletions test/integration/react-18/app/pages/suspense/thrown.js

This file was deleted.

14 changes: 0 additions & 14 deletions test/integration/react-18/app/pages/suspense/typing.tsx

This file was deleted.

@@ -1,3 +1,5 @@
// use tsx to cover typescript usage of next/dynamic + suspense: true

import React from 'react'
import dynamic from 'next/dynamic'

Expand Down
20 changes: 1 addition & 19 deletions test/integration/react-18/test/basics.js
Expand Up @@ -2,7 +2,7 @@

import webdriver from 'next-webdriver'
import cheerio from 'cheerio'
import { fetchViaHTTP, renderViaHTTP } from 'next-test-utils'
import { renderViaHTTP } from 'next-test-utils'

export default (context) => {
it('no warnings for image related link props', async () => {
Expand All @@ -17,24 +17,6 @@ export default (context) => {
expect(await browser.elementById('react-dom-version').text()).toMatch(/18/)
})

it('should works with suspense in ssg', async () => {
const res1 = await fetchViaHTTP(context.appPort, '/suspense/thrown')
const res2 = await fetchViaHTTP(context.appPort, '/suspense/no-thrown')

expect(res1.status).toBe(200)
expect(res2.status).toBe(200)
})

it('should render fallback without preloads on server side', async () => {
const html = await renderViaHTTP(context.appPort, '/suspense/no-preload')
const $ = cheerio.load(html)
const nextData = JSON.parse($('#__NEXT_DATA__').text())
const content = $('#__next').text()
// <Bar> is suspended
expect(content).toBe('fallback')
expect(nextData.dynamicIds).toBeUndefined()
})

it('useId() values should match on hydration', async () => {
const html = await renderViaHTTP(context.appPort, '/use-id')
const $ = cheerio.load(html)
Expand Down