diff --git a/packages/next-swc/crates/core/src/server_actions.rs b/packages/next-swc/crates/core/src/server_actions.rs index ec607f174f01d..56280a85d6990 100644 --- a/packages/next-swc/crates/core/src/server_actions.rs +++ b/packages/next-swc/crates/core/src/server_actions.rs @@ -898,13 +898,16 @@ impl VisitMut for ServerActions { // wrapped by a reference creation call. let create_ref_ident = private_ident!("createServerReference"); if !self.config.is_server { - // import createServerReference from 'private-next-rsc-action-client-wrapper' + // import { createServerReference } from + // 'private-next-rsc-action-client-wrapper' // createServerReference("action_id") new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, - specifiers: vec![ImportSpecifier::Default(ImportDefaultSpecifier { + specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { span: DUMMY_SP, local: create_ref_ident.clone(), + imported: None, + is_type_only: false, })], src: Box::new(Str { span: DUMMY_SP, @@ -986,9 +989,11 @@ impl VisitMut for ServerActions { let ensure_ident = private_ident!("ensureServerEntryExports"); new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, - specifiers: vec![ImportSpecifier::Default(ImportDefaultSpecifier { + specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { span: DUMMY_SP, local: ensure_ident.clone(), + imported: None, + is_type_only: false, })], src: Box::new(Str { span: DUMMY_SP, @@ -1056,7 +1061,7 @@ impl VisitMut for ServerActions { ); // import { createActionProxy } from 'private-next-rsc-action-proxy' - // createServerReference("action_id") + // createActionProxy("action_id") new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl { span: DUMMY_SP, specifiers: vec![ImportSpecifier::Named(ImportNamedSpecifier { diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js index 067c19bd7f501..11f21c43f6421 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/1/output.js @@ -1,6 +1,6 @@ /* __next_internal_action_entry_do_not_use__ foo */ import { createActionProxy } from "private-next-rsc-action-proxy"; export function foo() {} -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js index 9eba656fb0edf..bdd1975053c9e 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/2/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ bar */ import { createActionProxy } from "private-next-rsc-action-proxy"; 'use strict'; export function bar() {} -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ bar ]); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js index 5b742ce28a9d5..eab234f431c80 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/3/output.js @@ -1,6 +1,6 @@ /* __next_internal_action_entry_do_not_use__ x */ import { createActionProxy } from "private-next-rsc-action-proxy"; export const x = 1; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ x ]); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/4/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/4/output.js index 799cfbc141b10..a641bb04eca99 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/4/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/4/output.js @@ -4,5 +4,5 @@ export default class Component { return null; } } -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/5/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/5/output.js index 288bb0a3256c5..0e6caf6de54a8 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/5/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/5/output.js @@ -1,4 +1,4 @@ /* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy"; export * from 'foo'; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/6/output.js b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/6/output.js index 1dc0ea40d1675..795cff069312f 100644 --- a/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/6/output.js +++ b/packages/next-swc/crates/core/tests/errors/server-actions/server-graph/6/output.js @@ -1,4 +1,4 @@ /* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy"; export default (()=>{}); -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js index 5ff5df5f6e4ed..10bc8f50094d5 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/1/output.js @@ -1,5 +1,5 @@ // app/send.ts /* __next_internal_action_entry_do_not_use__ myAction,default */ import { createActionProxy } from "private-next-rsc-action-proxy"; -import createServerReference from "private-next-rsc-action-client-wrapper"; +import { createServerReference } from "private-next-rsc-action-client-wrapper"; export var myAction = createServerReference("e10665baac148856374b2789aceb970f66fec33e"); export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js index a3ac7d25bef5e..0880d7016ba62 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/2/output.js @@ -1,4 +1,4 @@ // app/send.ts /* __next_internal_action_entry_do_not_use__ foo */ import { createActionProxy } from "private-next-rsc-action-proxy"; -import createServerReference from "private-next-rsc-action-client-wrapper"; +import { createServerReference } from "private-next-rsc-action-client-wrapper"; export var foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js index 32b9d8367a4a2..4b1dcc1c3ae81 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/3/output.js @@ -1,5 +1,5 @@ /* __next_internal_action_entry_do_not_use__ sampleFunction,sampleFunction2,sampleFunction3,sampleFunction4 */ import { createActionProxy } from "private-next-rsc-action-proxy"; -import createServerReference from "private-next-rsc-action-client-wrapper"; +import { createServerReference } from "private-next-rsc-action-client-wrapper"; export var sampleFunction = createServerReference("bd336abe00c3c59da66acb696fc8e151d8e54ea4"); export var sampleFunction2 = createServerReference("a0c73dd6f5af839e3335c6b19262ecb86cca6af4"); export var sampleFunction3 = createServerReference("d4f2e95bc745b6500b439c0847003511748c8ece"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js index 799e3b427ffc5..bb52e3c80391b 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/client/4/output.js @@ -1,3 +1,3 @@ /* __next_internal_action_entry_do_not_use__ bar */ import { createActionProxy } from "private-next-rsc-action-proxy"; -import createServerReference from "private-next-rsc-action-client-wrapper"; +import { createServerReference } from "private-next-rsc-action-client-wrapper"; export var bar = createServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272"); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js index ce66f1f15ea15..639c6ad183372 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/10/output.js @@ -1,6 +1,6 @@ /* __next_internal_action_entry_do_not_use__ default */ import { createActionProxy } from "private-next-rsc-action-proxy"; export default async function foo() {} -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js index b0455322ae6dc..16dae3805e0e8 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/11/output.js @@ -1,6 +1,6 @@ /* __next_internal_action_entry_do_not_use__ default */ import { createActionProxy } from "private-next-rsc-action-proxy"; export default async function $$ACTION_0() {} -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js index a08633ca20425..a92d3aa7830a5 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/12/output.js @@ -1,7 +1,7 @@ /* __next_internal_action_entry_do_not_use__ default */ import { createActionProxy } from "private-next-rsc-action-proxy"; async function foo() {} export default foo; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js index 02de3e7b14256..55bebae6bf91b 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/13/output.js @@ -3,7 +3,7 @@ const foo = async function() {}; export default foo; const bar = async function() {}; export { bar }; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo, bar diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js index dd1abeb00a18c..7cc5f63d50992 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/14/output.js @@ -2,7 +2,7 @@ export async function foo() { async function bar() {} } -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js index fa74cf87bc23f..56f27cbc698b7 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/15/output.js @@ -3,7 +3,7 @@ export default $$ACTION_0 = async (a, b)=>{ console.log(a, b); }; var $$ACTION_0; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ $$ACTION_0 ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js index ae793593bd6cd..25f13f9621327 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/17/output.js @@ -2,7 +2,7 @@ export const foo = async ()=>{}; const bar = async ()=>{}; export { bar }; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo, bar diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js index 4dd595f286352..74cbde47fe377 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/20/output.js @@ -3,7 +3,7 @@ const [foo] = [ null ]; export default foo; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js index abca995a2b13d..c4de3250fa500 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/22/output.js @@ -3,7 +3,7 @@ import { validator } from 'auth'; export const action = validator(async ()=>{}); export default $$ACTION_0 = validator(async ()=>{}); var $$ACTION_0; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ action, $$ACTION_0 diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js index 92fdee096e88b..a14067d6dfa68 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/3/output.js @@ -3,7 +3,7 @@ export async function myAction(a, b, c) { console.log('a'); } -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ myAction ]); diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js index 8d440c7ac483c..403248b9f4609 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/4/output.js @@ -6,7 +6,7 @@ function d() {} function Foo() { async function e() {} } -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ a, b, diff --git a/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js b/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js index d1c4908b88711..1f354a4dc7fbd 100644 --- a/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js +++ b/packages/next-swc/crates/core/tests/fixture/server-actions/server/9/output.js @@ -6,7 +6,7 @@ async function bar() {} export { bar as baz }; async function qux() {} export { qux as default }; -import ensureServerEntryExports from "private-next-rsc-action-validate"; +import { ensureServerEntryExports } from "private-next-rsc-action-validate"; ensureServerEntryExports([ foo, bar, diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts index 76abdb0488074..a1095a8497f52 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/action-client-wrapper.ts @@ -5,12 +5,12 @@ import { callServer } from 'next/dist/client/app-call-server' // A noop wrapper to let the Flight client create the server reference. // See also: https://github.com/facebook/react/pull/26632 -export default function (id: string) { +export function createServerReference(id: string) { // Since we're using the Edge build of Flight client for SSR [1], here we need to // also use the same Edge build to create the reference. For the client bundle, // we use the default and let Webpack to resolve it to the correct version. // 1: https://github.com/vercel/next.js/blob/16eb80b0b0be13f04a6407943664b5efd8f3d7d0/packages/next/src/server/app-render/use-flight-response.tsx#L24-L26 - const { createServerReference } = ( + const { createServerReference: createServerReferenceImpl } = ( typeof window === 'undefined' ? // eslint-disable-next-line import/no-extraneous-dependencies require('react-server-dom-webpack/client.edge') @@ -18,5 +18,5 @@ export default function (id: string) { require('react-server-dom-webpack/client') ) as typeof import('react-server-dom-webpack/client') - return createServerReference(id, callServer) + return createServerReferenceImpl(id, callServer) } diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/action-validate.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/action-validate.ts index c77aa92c5aad6..08b9b53785f9f 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/action-validate.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/action-validate.ts @@ -1,4 +1,7 @@ -export default function ensureServerEntryExports(actions: any[]) { +// This function ensures that all the exported values are valid server actions, +// during the runtime. By definition all actions are required to be async +// functions, but here we can only check that they are functions. +export function ensureServerEntryExports(actions: any[]) { for (let i = 0; i < actions.length; i++) { const action = actions[i] if (typeof action !== 'function') {