Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not invoke server actions twice when dynamicIO is enabled #70784

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/next/src/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3038,7 +3038,8 @@ export default abstract class Server<
if (
!cache &&
!isPrefetchRSCRequest &&
routeModule?.definition.kind === RouteKind.APP_PAGE
routeModule?.definition.kind === RouteKind.APP_PAGE &&
!isServerAction
) {
req.headers[RSC_HEADER] = '1'
req.headers[NEXT_ROUTER_PREFETCH_HEADER] = '1'
Expand Down
5 changes: 5 additions & 0 deletions test/e2e/app-dir/dynamic-io/app/server-action/action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use server'

export async function action(value: string) {
return value
}
16 changes: 16 additions & 0 deletions test/e2e/app-dir/dynamic-io/app/server-action/page.tsx
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 test/e2e/app-dir/dynamic-io/dynamic-io.server-action.test.ts
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')
huozhi marked this conversation as resolved.
Show resolved Hide resolved
expect(await browser.elementByCss('p').text()).toBe('initial')
await browser.elementByCss('button').click()

await retry(async () => {
expect(await browser.elementByCss('p').text()).toBe('result')
})
})
})
Loading