Skip to content

Commit

Permalink
Adjust internal action proxy export (#54004)
Browse files Browse the repository at this point in the history
This PR changes the internal `createActionProxy` util from a default
export to a named export, as the default export could be problematic if
it's built without the "esModuleInterop" step.

---------

Co-authored-by: Balázs Orbán <info@balazsorban.com>
  • Loading branch information
shuding and balazsorban44 committed Aug 14, 2023
1 parent 380c17f commit cd95fe4
Show file tree
Hide file tree
Showing 37 changed files with 87 additions and 85 deletions.
12 changes: 7 additions & 5 deletions packages/next-swc/crates/core/src/server_actions.rs
Expand Up @@ -1053,13 +1053,15 @@ impl<C: Comments> VisitMut for ServerActions<C> {
},
);

// import __createActionProxy__ from 'private-next-rsc-action-proxy'
// import { createActionProxy } from 'private-next-rsc-action-proxy'
// 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: quote_ident!("__create_action_proxy__"),
local: quote_ident!("createActionProxy"),
imported: None,
is_type_only: false,
})],
src: Box::new(Str {
span: DUMMY_SP,
Expand Down Expand Up @@ -1173,7 +1175,7 @@ fn annotate_ident_as_action(
export_name: String,
maybe_orig_action_ident: Option<Ident>,
) {
// Add the proxy wrapper call `__create_action_proxy__($$id, $$bound, myAction,
// Add the proxy wrapper call `createActionProxy($$id, $$bound, myAction,
// maybe_orig_action)`.
let mut args = vec![
// $$id
Expand Down Expand Up @@ -1205,7 +1207,7 @@ fn annotate_ident_as_action(
span: DUMMY_SP,
expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: quote_ident!("__create_action_proxy__").as_callee(),
callee: quote_ident!("createActionProxy").as_callee(),
args: if let Some(orig_action_ident) = maybe_orig_action_ident {
args.push(ExprOrSpread {
spread: None,
Expand Down
@@ -1,9 +1,9 @@
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ $$ACTION_0 */ import { createActionProxy } from "private-next-rsc-action-proxy";
export default function App() {
async function fn(...args) {
return $$ACTION_0.apply(null, (fn.$$bound || []).concat(args));
}
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, fn, $$ACTION_0);
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, fn, $$ACTION_0);
return <div>App</div>;
}
export async function $$ACTION_0() {}
@@ -1,7 +1,7 @@
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
foo
]);
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
@@ -1,8 +1,8 @@
/* __next_internal_action_entry_do_not_use__ bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
bar
]);
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
@@ -1,7 +1,7 @@
/* __next_internal_action_entry_do_not_use__ x */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
x
]);
__create_action_proxy__("b78c261f135a7a852508c2920bd7228020ff4bd7", null, x);
createActionProxy("b78c261f135a7a852508c2920bd7228020ff4bd7", null, x);
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy";
export default class Component {
render() {
return null;
Expand Down
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([]);
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([]);
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import { createActionProxy } from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export var $$ACTION_1 = ()=>{};
var $$ACTION_0;
@@ -1,5 +1,5 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import { createActionProxy } from "private-next-rsc-action-proxy";
const foo = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", null, $$ACTION_0, $$ACTION_1), $$ACTION_0);
export var $$ACTION_1 = async ()=>{
'use strict';
};
Expand Down
@@ -1,5 +1,5 @@
// app/send.ts
/* __next_internal_action_entry_do_not_use__ myAction,default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
export var myAction = createServerReference("e10665baac148856374b2789aceb970f66fec33e");
export default createServerReference("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d");
@@ -1,4 +1,4 @@
// app/send.ts
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
export var foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b");
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ sampleFunction,sampleFunction2,sampleFunction3,sampleFunction4 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
export var sampleFunction = createServerReference("bd336abe00c3c59da66acb696fc8e151d8e54ea4");
export var sampleFunction2 = createServerReference("a0c73dd6f5af839e3335c6b19262ecb86cca6af4");
Expand Down
@@ -1,10 +1,10 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_0,$$ACTION_2 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ $$ACTION_0,$$ACTION_2 */ import { createActionProxy } from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
export function Item({ id1 , id2 }) {
async function deleteItem(...args) {
return $$ACTION_0.apply(null, (deleteItem.$$bound || []).concat(args));
}
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
id1,
id2
], deleteItem, $$ACTION_0);
Expand All @@ -19,7 +19,7 @@ export default function Home() {
name: 'John',
test: 'test'
};
const action = ($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), __create_action_proxy__("9878bfa39811ca7650992850a8751f9591b6a557", [
const action = ($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", [
info.name,
info.test
], $$ACTION_1, $$ACTION_2), $$ACTION_1);
Expand Down
@@ -1,7 +1,7 @@
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
foo
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
@@ -1,7 +1,7 @@
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
$$ACTION_0
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
@@ -1,8 +1,8 @@
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __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";
ensureServerEntryExports([
foo
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ default,bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ default,bar */ import { createActionProxy } from "private-next-rsc-action-proxy";
const foo = async function() {};
export default foo;
const bar = async function() {};
Expand All @@ -8,5 +8,5 @@ ensureServerEntryExports([
foo,
bar
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
@@ -1,9 +1,9 @@
/* __next_internal_action_entry_do_not_use__ foo */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ foo */ import { createActionProxy } from "private-next-rsc-action-proxy";
export async function foo() {
async function bar() {}
}
import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ default */ import { createActionProxy } from "private-next-rsc-action-proxy";
export default $$ACTION_0 = async (a, b)=>{
console.log(a, b);
};
Expand All @@ -7,4 +7,4 @@ import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
$$ACTION_0
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, $$ACTION_0);
@@ -1,9 +1,9 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_2,$$ACTION_4 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_2,$$ACTION_4 */ import { createActionProxy } from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1 , id2 }) {
const v2 = id2;
const deleteItem = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
const deleteItem = ($$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
], $$ACTION_0, $$ACTION_1), $$ACTION_0);
Expand All @@ -19,15 +19,15 @@ const f = (x)=>{
async function g(...args) {
return $$ACTION_2.apply(null, (g.$$bound || []).concat(args));
}
__create_action_proxy__("9878bfa39811ca7650992850a8751f9591b6a557", [
createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", [
x
], g, $$ACTION_2);
};
export async function $$ACTION_2($$ACTION_ARG_0, y, ...z) {
return $$ACTION_ARG_0 + y + z[0];
}
const g = (x)=>{
f = ($$ACTION_3 = async (...args)=>$$ACTION_4.apply(null, ($$ACTION_3.$$bound || []).concat(args)), __create_action_proxy__("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
f = ($$ACTION_3 = async (...args)=>$$ACTION_4.apply(null, ($$ACTION_3.$$bound || []).concat(args)), createActionProxy("9c0dd1f7c2b3f41d32e10f5c437de3d67ad32c6c", [
x
], $$ACTION_3, $$ACTION_4), $$ACTION_3);
};
Expand Down
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ foo,bar */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ foo,bar */ import { createActionProxy } from "private-next-rsc-action-proxy";
export const foo = async ()=>{};
const bar = async ()=>{};
export { bar };
Expand All @@ -7,5 +7,5 @@ ensureServerEntryExports([
foo,
bar
]);
__create_action_proxy__("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
__create_action_proxy__("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
createActionProxy("ab21efdafbe611287bc25c0462b1e0510d13e48b", null, foo);
createActionProxy("ac840dcaf5e8197cb02b7f3a43c119b7a770b272", null, bar);
@@ -1,11 +1,11 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ $$ACTION_1,$$ACTION_3 */ import { createActionProxy } from "private-next-rsc-action-proxy";
import deleteFromDb from 'db';
const v1 = 'v1';
export function Item({ id1, id2 }) {
const v2 = id2;
return <>

<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
id1,
v2
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>
Expand All @@ -16,7 +16,7 @@ export function Item({ id1, id2 }) {

<Button action={$$ACTION_2 = async function(...args) {
return $$ACTION_3.apply(null, ($$ACTION_2.$$bound || []).concat(args));
}, __create_action_proxy__("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
}, createActionProxy("56a859f462d35a297c46a1bbd1e6a9058c104ab8", [
id1,
v2
], $$ACTION_2, $$ACTION_3), $$ACTION_2}>
Expand Down
@@ -1,8 +1,8 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import { createActionProxy } from "private-next-rsc-action-proxy";
export function Item({ value }) {
return <>

<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), __create_action_proxy__("188d5d945750dc32e2c842b93c75a65763d4a922", [
<Button action={$$ACTION_0 = async (...args)=>$$ACTION_1.apply(null, ($$ACTION_0.$$bound || []).concat(args)), createActionProxy("188d5d945750dc32e2c842b93c75a65763d4a922", [
value
], $$ACTION_0, $$ACTION_1), $$ACTION_0}>

Expand Down
@@ -1,14 +1,14 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_0,$$ACTION_2 */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ $$ACTION_0,$$ACTION_2 */ import { createActionProxy } from "private-next-rsc-action-proxy";
async function myAction(...args) {
return $$ACTION_0.apply(null, (myAction.$$bound || []).concat(args));
}
__create_action_proxy__("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
createActionProxy("6d53ce510b2e36499b8f56038817b9bad86cabb4", null, myAction, $$ACTION_0);
export async function $$ACTION_0(a, b, c) {
console.log('a');
}
export default function Page() {
return <Button action={myAction}>Delete</Button>;
}
export const action = withValidate(($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), __create_action_proxy__("9878bfa39811ca7650992850a8751f9591b6a557", null, $$ACTION_1, $$ACTION_2), $$ACTION_1));
export const action = withValidate(($$ACTION_1 = async (...args)=>$$ACTION_2.apply(null, ($$ACTION_1.$$bound || []).concat(args)), createActionProxy("9878bfa39811ca7650992850a8751f9591b6a557", null, $$ACTION_1, $$ACTION_2), $$ACTION_1));
export var $$ACTION_2 = async ()=>{};
var $$ACTION_1;
@@ -1,4 +1,4 @@
/* __next_internal_action_entry_do_not_use__ default */ import __create_action_proxy__ from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ default */ import { createActionProxy } from "private-next-rsc-action-proxy";
const [foo] = [
null
];
Expand All @@ -7,4 +7,4 @@ import ensureServerEntryExports from "private-next-rsc-action-validate";
ensureServerEntryExports([
foo
]);
__create_action_proxy__("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);
createActionProxy("c18c215a6b7cdc64bf709f3a714ffdef1bf9651d", null, foo);

0 comments on commit cd95fe4

Please sign in to comment.