forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(next-swc): lint for
ssr: false
in server components (vercel#70378
- Loading branch information
Showing
18 changed files
with
192 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...m-transforms/tests/errors/react-server-components/server-graph/dynamic-ssr-false/input.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
export default function () { | ||
return dynamic(() => import('client-only'), { ssr: false }) | ||
} |
6 changes: 6 additions & 0 deletions
6
...-transforms/tests/errors/react-server-components/server-graph/dynamic-ssr-false/output.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import dynamic from 'next/dynamic'; | ||
export default function() { | ||
return dynamic(()=>import('client-only'), { | ||
ssr: false | ||
}); | ||
} |
7 changes: 7 additions & 0 deletions
7
...nsforms/tests/errors/react-server-components/server-graph/dynamic-ssr-false/output.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
x `ssr: false` is not allowed with `next/dynamic` in Server Components. Please move it into a client component. | ||
,-[input.js:4:1] | ||
3 | export default function () { | ||
4 | return dynamic(() => import('client-only'), { ssr: false }) | ||
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
5 | } | ||
`---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
test/development/app-dir/server-component-next-dynamic-ssr-false/app/client.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use client' | ||
|
||
export default function Client() { | ||
return 'client' | ||
} |
7 changes: 7 additions & 0 deletions
7
test/development/app-dir/server-component-next-dynamic-ssr-false/app/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Root({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/development/app-dir/server-component-next-dynamic-ssr-false/app/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import dynamic from 'next/dynamic' | ||
|
||
const DynamicClient = dynamic(() => import('./client'), { ssr: false }) | ||
|
||
export default function Page() { | ||
return <DynamicClient /> | ||
} |
52 changes: 52 additions & 0 deletions
52
...r/server-component-next-dynamic-ssr-false/server-component-next-dynamic-ssr-false.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { | ||
assertHasRedbox, | ||
getRedboxDescription, | ||
getRedboxSource, | ||
} from 'next-test-utils' | ||
|
||
describe('app-dir - server-component-next-dynamic-ssr-false', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should error when use dynamic ssr:false in server component', async () => { | ||
const browser = await next.browser('/') | ||
await assertHasRedbox(browser) | ||
const redbox = { | ||
description: await getRedboxDescription(browser), | ||
source: await getRedboxSource(browser), | ||
} | ||
|
||
expect(redbox.description).toBe('Failed to compile') | ||
if (process.env.TURBOPACK) { | ||
expect(redbox.source).toMatchInlineSnapshot(` | ||
"./app/page.js:3:23 | ||
Ecmascript file had an error | ||
1 | import dynamic from 'next/dynamic' | ||
2 | | ||
> 3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false }) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 | | ||
5 | export default function Page() { | ||
6 | return <DynamicClient /> | ||
\`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a client component." | ||
`) | ||
} else { | ||
expect(redbox.source).toMatchInlineSnapshot(` | ||
"./app/page.js | ||
Error: x \`ssr: false\` is not allowed with \`next/dynamic\` in Server Components. Please move it into a client component. | ||
,-[3:1] | ||
1 | import dynamic from 'next/dynamic' | ||
2 | | ||
3 | const DynamicClient = dynamic(() => import('./client'), { ssr: false }) | ||
: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
4 | | ||
5 | export default function Page() { | ||
6 | return <DynamicClient /> | ||
\`----" | ||
`) | ||
} | ||
}) | ||
}) |
4 changes: 2 additions & 2 deletions
4
test/e2e/app-dir/dynamic/app/dynamic-mixed-ssr-false/ssr-false-module/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import Client from './ssr-false-client' | ||
import Server from './ssr-false-server' | ||
// import Server from './ssr-false-server' | ||
|
||
export default function Comp() { | ||
return ( | ||
<> | ||
<Client /> | ||
<Server /> | ||
{/* <Server /> */} | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client' | ||
|
||
import dynamic from 'next/dynamic' | ||
|
||
const Client1 = dynamic(() => import('./client')) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
test/e2e/app-dir/dynamic/app/dynamic/text-dynamic-no-ssr-server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import TextClient from './text-client' | ||
// import TextClient from './text-client' | ||
|
||
export default function Dynamic() { | ||
return ( | ||
<> | ||
<p id="css-text-dynamic-no-ssr-server"> | ||
next-dynamic dynamic no ssr on server | ||
</p> | ||
<TextClient /> | ||
</> | ||
) | ||
} | ||
// export default function Dynamic() { | ||
// return ( | ||
// <> | ||
// <p id="css-text-dynamic-no-ssr-server"> | ||
// next-dynamic dynamic no ssr on server | ||
// </p> | ||
// <TextClient /> | ||
// </> | ||
// ) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
test/e2e/app-dir/missing-suspense-with-csr-bailout/app/dynamic/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client' | ||
|
||
import dynamic from 'next/dynamic' | ||
|
||
const Dynamic = dynamic(() => import('./dynamic'), { | ||
|
10 changes: 10 additions & 0 deletions
10
test/integration/next-image-new/app-dir/app/dynamic-static-img/async-image.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use client' | ||
|
||
import dynamic from 'next/dynamic' | ||
|
||
export const DynamicStaticImg = dynamic( | ||
() => import('../../components/static-img'), | ||
{ | ||
ssr: false, | ||
} | ||
) |
Oops, something went wrong.