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

Fix Server Reference being double registered #61244

Merged
merged 2 commits into from
Jan 27, 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
Original file line number Diff line number Diff line change
Expand Up @@ -1021,11 +1021,11 @@ impl<C: Comments> VisitMut for ServerActions<C> {
}

if self.has_action {
let actions = if self.in_action_file {
self.exported_idents.iter().map(|e| e.1.clone()).collect()
} else {
self.export_actions.clone()
let mut actions = self.export_actions.clone();
if self.in_action_file {
actions.extend(self.exported_idents.iter().map(|e| e.1.clone()));
};

let actions = actions
.into_iter()
.map(|name| (generate_action_id(&self.file_name, &name), name))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0);
export async function $$ACTION_0() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default $$ACTION_0 = createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1);
var $$ACTION_0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo","ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const foo = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0);
export async function $$ACTION_0() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","9878bfa39811ca7650992850a8751f9591b6a557":"$$ACTION_2","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","f14702b5a021dd117f7ec7a3c838f397c2046d3b":"action"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
import { validator } from 'auth';
export const action = validator(createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use server'

export const dec = async (value) => {
return value - 1
}

// Test case for https://github.com/vercel/next.js/issues/54655
export default dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/* __next_internal_action_entry_do_not_use__ {"28baf972d345b86b747ad0df73d75a0088a42214":"dec","6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$ACTION_0","c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const dec = createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0);
export async function $$ACTION_0(value) {
return value - 1;
}
// Test case for https://github.com/vercel/next.js/issues/54655
export default dec;
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
dec,
dec
]);
createActionProxy("28baf972d345b86b747ad0df73d75a0088a42214", dec);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", dec);
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
/* eslint-disable import/no-extraneous-dependencies */
import { registerServerReference } from 'react-server-dom-webpack/server.edge'

const SERVER_REFERENCE_TAG = Symbol.for('react.server.reference')

function isServerReference(reference: any) {
return reference && reference.$$typeof === SERVER_REFERENCE_TAG
}

export function createActionProxy(id: string, action: any) {
// Avoid registering the same action twice
if (isServerReference(action)) {
return action
}

return registerServerReference(action, id, null)
}
8 changes: 7 additions & 1 deletion test/e2e/app-dir/actions/app/server/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ export async function slowInc(value) {
return value + 1
}

export default async function dec(value) {
export const dec = async (value) => {
return value - 1
}

// Test case for https://github.com/vercel/next.js/issues/54655
export default dec

export async function redirectAction(formData) {
'use server'
redirect(
Expand All @@ -20,3 +23,6 @@ export async function redirectAction(formData) {
formData.get('hidden-info')
)
}

// Test case for https://github.com/vercel/next.js/issues/61183
export const dummyServerAction = () => new Promise((r) => setTimeout(r, 2000))
Loading