-
Notifications
You must be signed in to change notification settings - Fork 27.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid server action function indirection in Turbopack
As a follow-up to #71572, this PR replaces the server action function indirection in Turbopack's generated action loader module with a direct re-export of the actions, using the action ID as export name. The server action identity test that was added in #71572 was not sufficient to uncover that Turbopack was still using the wrapper functions. To fix that, we've added another test here, which uses a combination of `"use server"` and `"use cache"` functions in a page. This test does fail in Turbopack without the loader changes. In addition, the building of the server reference manifest is adjusted to account for the new structure that expects `{moduleId: string, async: boolean}` instead of `string`. The `async` flag is set based on the loader's chunk item. I believe this is currently always `false` though. However, Turbopack can still resolve the modules just fine, even when there are outgoing async connections.
- Loading branch information
1 parent
ba50f4c
commit 0d3aa7c
Showing
8 changed files
with
83 additions
and
31 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
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: 22 additions & 0 deletions
22
test/e2e/app-dir/use-cache/app/with-server-action/form.tsx
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,22 @@ | ||
'use client' | ||
|
||
import { ReactNode } from 'react' | ||
import { useActionState } from 'react' | ||
|
||
export function Form({ | ||
action, | ||
children, | ||
}: { | ||
action: () => Promise<string> | ||
children: ReactNode | ||
}) { | ||
const [result, formAction] = useActionState(action, 'initial') | ||
|
||
return ( | ||
<form action={formAction}> | ||
<button>Submit</button> | ||
<p>{result}</p> | ||
{children} | ||
</form> | ||
) | ||
} |
17 changes: 17 additions & 0 deletions
17
test/e2e/app-dir/use-cache/app/with-server-action/page.tsx
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,17 @@ | ||
import { Form } from './form' | ||
|
||
async function action() { | ||
'use server' | ||
|
||
return 'result' | ||
} | ||
|
||
export default async function Page() { | ||
'use cache' | ||
|
||
return ( | ||
<Form action={action}> | ||
<p>{Date.now()}</p> | ||
</Form> | ||
) | ||
} |
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