Skip to content

Commit 648d8f8

Browse files
committed
Update tests
1 parent 1399914 commit 648d8f8

File tree

12 files changed

+70
-20
lines changed

12 files changed

+70
-20
lines changed

crates/next-custom-transforms/src/transforms/react_server_components.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
303303
_ => (format!("\"{source}\" is deprecated."), span),
304304
},
305305
RSCErrorKind::NextSsrDynamicFalseNotAllowed(span) => (
306-
"{ ssr: false } is not allowed in Server Components. Use { ssr: true } instead."
306+
"`ssr: false` is not allowed with `next/dynamic` in Server Components. Please move it into a client component."
307307
.to_string(),
308308
span,
309309
),
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
x { ssr: false } is not allowed in Server Components. Use { ssr: true } instead.
1+
x `ssr: false` is not allowed with `next/dynamic` in Server Components. Please move it into a client component.
22
,-[input.js:4:1]
33
3 | export default function () {
44
4 | return dynamic(() => import('client-only'), { ssr: false })
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use client'
2+
3+
export default function Client() {
4+
return 'client'
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Root({ children }) {
2+
return (
3+
<html>
4+
<body>{children}</body>
5+
</html>
6+
)
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import dynamic from 'next/dynamic'
2+
3+
const DynamicClient = dynamic(() => import('./client'), { ssr: false })
4+
5+
export default function Page() {
6+
return <DynamicClient />
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { nextTestSetup } from 'e2e-utils'
2+
import {
3+
assertHasRedbox,
4+
getRedboxDescription,
5+
getRedboxSource,
6+
} from 'next-test-utils'
7+
8+
describe('app-dir - server-component-next-dynamic-ssr-false', () => {
9+
const { next } = nextTestSetup({
10+
files: __dirname,
11+
})
12+
13+
it('should error when use dynamic ssr:false in server component', async () => {
14+
const browser = await next.browser('/')
15+
await assertHasRedbox(browser)
16+
const redbox = {
17+
description: await getRedboxDescription(browser),
18+
source: await getRedboxSource(browser),
19+
}
20+
21+
expect(redbox.description).toBe('Failed to compile')
22+
expect(redbox.source).toMatchInlineSnapshot(`
23+
"./app/page.js
24+
Error: x \`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a client component.
25+
,-[3:1]
26+
1 | import dynamic from "next/dynamic"
27+
2 |
28+
3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false })
29+
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
4 |
31+
5 | export default function Page() {
32+
6 | return <DynamicClient />
33+
\`----"
34+
`)
35+
})
36+
})

test/e2e/app-dir/dynamic/app/dynamic/async-client/page.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client'
2+
13
import dynamic from 'next/dynamic'
24

35
const Client1 = dynamic(() => import('./client'))

test/e2e/app-dir/dynamic/dynamic.test.ts

-13
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,10 @@ describe('app dir - next/dynamic', () => {
3333
expect(serverContent).toContain('next-dynamic dynamic on client')
3434
expect(serverContent).toContain('next-dynamic server import client')
3535
expect(serverContent).not.toContain('next-dynamic dynamic no ssr on client')
36-
37-
// expect(serverContent).not.toContain('next-dynamic dynamic no ssr on server')
38-
39-
// client component under server component with ssr: false will not be rendered either in flight or SSR
40-
// expect($.html()).not.toContain('client component under sever no ssr')
4136
})
4237

4338
it('should handle next/dynamic in hydration correctly', async () => {
44-
const selector = 'body div'
4539
const browser = await next.browser('/dynamic')
46-
const clientContent = await browser.elementByCss(selector).text()
47-
// expect(clientContent).toContain('next-dynamic dynamic no ssr on server')
48-
// expect(clientContent).toContain('client component under sever no ssr')
4940
await browser.waitForElementByCss('#css-text-dynamic-no-ssr-client')
5041

5142
expect(
@@ -127,9 +118,6 @@ describe('app dir - next/dynamic', () => {
127118
)
128119
// noSSR should not show up in browser
129120
const browser = await next.browser('/dynamic-mixed-ssr-false/client')
130-
// expect(
131-
// await browser.elementByCss('#ssr-false-server-module').text()
132-
// ).toBe('ssr-false-server-module-text')
133121
expect(
134122
await browser.elementByCss('#ssr-false-client-module').text()
135123
).toBe('ssr-false-client-module-text')
@@ -139,7 +127,6 @@ describe('app dir - next/dynamic', () => {
139127
const pageServerChunk = await next.readFile(
140128
'.next/server/app/dynamic-mixed-ssr-false/client/page.js'
141129
)
142-
// expect(pageServerChunk).not.toContain('ssr-false-server-module-text')
143130
expect(pageServerChunk).not.toContain('ssr-false-client-module-text')
144131
}
145132
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use client'
2+
3+
import dynamic from 'next/dynamic'
4+
5+
export const DynamicStaticImg = dynamic(
6+
() => import('../../components/static-img'),
7+
{
8+
ssr: false,
9+
}
10+
)

test/integration/next-image-new/app-dir/app/dynamic-static-img/page.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import dynamic from 'next/dynamic'
2-
3-
const DynamicStaticImg = dynamic(() => import('../../components/static-img'), {
4-
ssr: false,
5-
})
1+
import { DynamicStaticImg } from './async-image'
62

73
export default () => {
84
return (

0 commit comments

Comments
 (0)