-
Notifications
You must be signed in to change notification settings - Fork 27.1k
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 (#70784)
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
b50a0dd
commit 1b644e0
Showing
4 changed files
with
41 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,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/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', () => { | ||
const { next } = nextTestSetup({ | ||
files: __dirname, | ||
}) | ||
|
||
it('should not fail decoding server action arguments', async () => { | ||
const browser = await next.browser('/server-action') | ||
expect(await browser.elementByCss('p').text()).toBe('initial') | ||
await browser.elementByCss('button').click() | ||
|
||
await retry(async () => { | ||
expect(await browser.elementByCss('p').text()).toBe('result') | ||
}) | ||
}) | ||
}) |