-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not invoke server actions twice when
dynamicIO
is enabled
In dev mode, when dynamic IO is enabled, we seed a prefetch cache scope for non-prefetch requests (via #70408). We must omit server action requests from this cache seeding though, because it would lead to the action handler being called twice. This is not intended in general for any action, and specificially fails in the second invocation while decoding the request form data with `Error: Unexpected end of JSON input` in `initializeModelChunk`, because the request body was already consumed in the first invocation.
- Loading branch information
1 parent
d5fd4c1
commit 570aaf4
Showing
6 changed files
with
59 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use server' | ||
|
||
export async function action(value: string) { | ||
return value | ||
} |
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,8 @@ | ||
import { ReactNode } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
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,16 @@ | ||
'use client' | ||
|
||
import { useActionState } from 'react' | ||
import { action } from './action' | ||
|
||
export default function Page() { | ||
const [result, formAction] = useActionState(() => action('result'), 'initial') | ||
|
||
return ( | ||
<form action={formAction}> | ||
<h1>Server Action with Dynamic IO</h1> | ||
<button>Submit</button> | ||
<p>{result}</p> | ||
</form> | ||
) | ||
} |
18 changes: 18 additions & 0 deletions
18
test/e2e/app-dir/dynamic-io-server-action/dynamic-io-server-action.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,18 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { retry } from 'next-test-utils' | ||
|
||
describe('dynamic-io-server-action', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not fail decoding server action arguments', async () => { | ||
const browser = await next.browser('/') | ||
expect(await browser.elementByCss('p').text()).toBe('initial') | ||
await browser.elementByCss('button').click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('p').text()).toBe('result') | ||
}) | ||
}) | ||
}) |
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 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
dynamicIO: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |