-
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.
Avoid server action function indirection in Turbopack (#71628)
- Loading branch information
1 parent
e9b18d6
commit 51d6e76
Showing
9 changed files
with
92 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> | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
test/e2e/app-dir/use-cache/app/with-server-action/layout.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,14 @@ | ||
import { connection } from 'next/server' | ||
|
||
export default async function DynamicLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
// TODO: This is a workaround for Turbopack. Figure out why this fails during | ||
// prerendering with: | ||
// TypeError: Cannot read properties of undefined (reading 'Form') | ||
await connection() | ||
|
||
return children | ||
} |
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