-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable server action transform in pages router (#71028)
- Loading branch information
Showing
6 changed files
with
86 additions
and
2 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
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
47 changes: 47 additions & 0 deletions
47
test/e2e/app-dir/action-in-pages-router/action-in-pages-router.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,47 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { assertNoRedbox, retry } from 'next-test-utils' | ||
|
||
describe('app-dir - action-in-pages-router', () => { | ||
const { next, isNextStart } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not error on fake server action in pages router', async () => { | ||
const browser = await next.browser('/foo') | ||
const button = await browser.elementByCss('button') | ||
await button.click() | ||
|
||
await retry(async () => { | ||
const browserLogText = (await browser.log()) | ||
.map((item) => item.message) | ||
.join('') | ||
// This is a fake server action, a simple function so it can still work | ||
expect(browserLogText).toContain('action:foo') | ||
await assertNoRedbox(browser) | ||
}) | ||
}) | ||
|
||
if (isNextStart) { | ||
// Disabling for turbopack because the chunk path are different | ||
if (!process.env.TURBOPACK) { | ||
it('should not contain server action in page bundle', async () => { | ||
const pageBundle = await next.readFile('.next/server/pages/foo.js') | ||
// Should not contain the RSC client import source for the server action | ||
expect(pageBundle).not.toContain('react-server-dom-webpack/client') | ||
}) | ||
} | ||
|
||
it('should not contain server action in manifest', async () => { | ||
if (process.env.TURBOPACK) { | ||
const manifest = JSON.parse( | ||
await next.readFile('.next/server/server-reference-manifest.json') | ||
) | ||
expect(Object.keys(manifest.node).length).toBe(0) | ||
} else { | ||
expect( | ||
await next.hasFile('.next/server/server-reference-manifest.json') | ||
).toBe(false) | ||
} | ||
}) | ||
} | ||
}) |
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 server' | ||
|
||
export async function actionFoo() { | ||
return 'action:foo' | ||
} |
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,18 @@ | ||
import { actionFoo } from '../actions' | ||
|
||
export default function Page() { | ||
return ( | ||
<button | ||
onClick={() => { | ||
actionFoo().then((v) => console.log(v)) | ||
}} | ||
> | ||
hello | ||
</button> | ||
) | ||
} | ||
|
||
// Keep route as dynamic | ||
export async function getServerSideProps() { | ||
return { props: {} } | ||
} |