-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix shared action module in two layers (#51510)
Currently an "action module" (files with `"use server"` on top) can be imported by both the server and client layers. In that case, we can't fork that action module into two modules (one on the server layer, one on the action layer), but only create it once on the server layer. This ensures that the action module instance doesn't get forked. Closes #50801. fix NEXT-1265
- Loading branch information
Showing
6 changed files
with
106 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
'use server' | ||
|
||
import { revalidatePath } from 'next/cache' | ||
|
||
let x = 0 | ||
|
||
export async function inc() { | ||
++x | ||
revalidatePath('/shared') | ||
} | ||
|
||
export async function get() { | ||
return x | ||
} |
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,13 @@ | ||
'use client' | ||
|
||
import { inc } from './action' | ||
|
||
export function Client() { | ||
return ( | ||
<form> | ||
<button id="client-inc" formAction={inc}> | ||
Inc | ||
</button> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { Server } from './server' | ||
import { Client } from './client' | ||
|
||
export default async function Page() { | ||
return ( | ||
<> | ||
<hr /> | ||
<Server /> | ||
<hr /> | ||
<Client /> | ||
</> | ||
) | ||
} |
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,15 @@ | ||
import { inc, get } from './action' | ||
|
||
export async function Server() { | ||
const x = await get() | ||
return ( | ||
<> | ||
<h2 id="value">Value = {x}</h2> | ||
<form> | ||
<button id="server-inc" formAction={inc}> | ||
Inc | ||
</button> | ||
</form> | ||
</> | ||
) | ||
} |