-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust transforms for cached functions imported from client components (
#71401) This fixes the server reference ID generation in client modules so that they can be import and called from client components. In addition, support for cached functions with decoupled export declarations is added.
- Loading branch information
1 parent
a6cd98a
commit ac9ee5d
Showing
8 changed files
with
100 additions
and
17 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
2 changes: 2 additions & 0 deletions
2
crates/next-custom-transforms/tests/fixture/server-actions/client/6/input.js
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use cache' | ||
|
||
export async function foo() {} | ||
const bar = async () => {} | ||
export { bar } |
3 changes: 2 additions & 1 deletion
3
crates/next-custom-transforms/tests/fixture/server-actions/client/6/output.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
crates/next-custom-transforms/tests/fixture/server-actions/server/34/input.js
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use cache' | ||
|
||
export async function foo() { | ||
return 'data' | ||
} | ||
export async function foo() {} | ||
const bar = async () => {} | ||
export { bar } |
9 changes: 5 additions & 4 deletions
9
crates/next-custom-transforms/tests/fixture/server-actions/server/34/output.js
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 |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/* __next_internal_action_entry_do_not_use__ {"3128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
/* __next_internal_action_entry_do_not_use__ {"3128060c414d59f8552e4788b846c0d2b7f74743":"$$RSC_SERVER_CACHE_0","951c375b4a6a6e89d67b743ec5808127cfde405d":"$$RSC_SERVER_CACHE_1"} */ import { registerServerReference } from "private-next-rsc-server-reference"; | ||
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption"; | ||
import { cache as $$cache__ } from "private-next-rsc-cache-wrapper"; | ||
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "3128060c414d59f8552e4788b846c0d2b7f74743", async function foo() { | ||
return 'data'; | ||
}); | ||
export var $$RSC_SERVER_CACHE_0 = $$cache__("default", "3128060c414d59f8552e4788b846c0d2b7f74743", async function foo() {}); | ||
export var foo = registerServerReference($$RSC_SERVER_CACHE_0, "3128060c414d59f8552e4788b846c0d2b7f74743", null); | ||
export var $$RSC_SERVER_CACHE_1 = $$cache__("default", "951c375b4a6a6e89d67b743ec5808127cfde405d", async function() {}); | ||
const bar = registerServerReference($$RSC_SERVER_CACHE_1, "951c375b4a6a6e89d67b743ec5808127cfde405d", null); | ||
export { bar }; |
15 changes: 15 additions & 0 deletions
15
test/e2e/app-dir/use-cache/app/imported-from-client/cached.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,15 @@ | ||
'use cache' | ||
|
||
export async function bar() { | ||
const v = Math.random() | ||
console.log(v) | ||
return v | ||
} | ||
|
||
const baz = async () => { | ||
const v = Math.random() | ||
console.log(v) | ||
return v | ||
} | ||
|
||
export { baz } |
32 changes: 32 additions & 0 deletions
32
test/e2e/app-dir/use-cache/app/imported-from-client/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,32 @@ | ||
'use client' | ||
|
||
import { useActionState } from 'react' | ||
import { bar, baz } from './cached' | ||
|
||
export default function Page() { | ||
const [result, dispatch] = useActionState< | ||
[number, number], | ||
'submit' | 'reset' | ||
>( | ||
async (_state, event) => { | ||
if (event === 'reset') { | ||
return [0, 0] | ||
} | ||
|
||
return [await bar(), await baz()] | ||
}, | ||
[0, 0] | ||
) | ||
|
||
return ( | ||
<form action={() => dispatch('submit')}> | ||
<button id="submit-button">Click me</button> | ||
<p> | ||
{result[0]} {result[1]} | ||
</p> | ||
<button id="reset-button" formAction={() => dispatch('reset')}> | ||
Reset | ||
</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