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

backport: server actions #69612

Merged
merged 4 commits into from
Sep 3, 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 @@ -50,6 +50,7 @@ impl CustomTransformer for NextServerActions {
Config {
is_react_server_layer: matches!(self.transform, ActionsTransform::Server),
enabled: true,
hash_salt: "".into(),
},
ctx.comments.clone(),
);
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ fn react_server_actions_server_errors(input: PathBuf) {
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: true,
enabled: true
enabled: true,
hash_salt: "".into()
},
tr.comments.as_ref().clone(),
)
Expand Down Expand Up @@ -214,7 +215,8 @@ fn react_server_actions_client_errors(input: PathBuf) {
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: false,
enabled: true
enabled: true,
hash_salt: "".into()
},
tr.comments.as_ref().clone(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,8 @@ fn server_actions_server_fixture(input: PathBuf) {
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: true,
enabled: true
enabled: true,
hash_salt: "".into()
},
_tr.comments.as_ref().clone(),
)
Expand All @@ -405,7 +406,8 @@ fn server_actions_client_fixture(input: PathBuf) {
&FileName::Real("/app/item.js".into()),
server_actions::Config {
is_react_server_layer: false,
enabled: true
enabled: true,
hash_salt: "".into()
},
_tr.comments.as_ref().clone(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
let a, f;
function Comp(b, c, ...g) {
return registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
b,
c,
g,
b
g
]));
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, e) {
Expand All @@ -23,19 +23,19 @@ export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) {
console.log(...window, {
window
});
console.log(a, $$ACTION_ARG_2, action2);
console.log(a, $$ACTION_ARG_0, action2);
var action2 = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
$$ACTION_ARG_0,
$$ACTION_ARG_1,
d,
f,
$$ACTION_ARG_1
$$ACTION_ARG_2
]));
return [
action2,
registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
action2,
$$ACTION_ARG_0,
$$ACTION_ARG_1,
d
]))
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc
let a, f;
export async function action0(b, c, ...g) {
return registerServerReference("9878bfa39811ca7650992850a8751f9591b6a557", $$ACTION_2).bind(null, encryptActionBoundArgs("9878bfa39811ca7650992850a8751f9591b6a557", [
b,
c,
g,
b
g
]));
}
export async function $$ACTION_0($$ACTION_CLOSURE_BOUND, e) {
Expand All @@ -23,18 +23,18 @@ export async function $$ACTION_2($$ACTION_CLOSURE_BOUND, d) {
console.log(...window, {
window
});
console.log(a, $$ACTION_ARG_2, action2);
console.log(a, $$ACTION_ARG_0, action2);
var action2 = registerServerReference("6d53ce510b2e36499b8f56038817b9bad86cabb4", $$ACTION_0).bind(null, encryptActionBoundArgs("6d53ce510b2e36499b8f56038817b9bad86cabb4", [
$$ACTION_ARG_0,
$$ACTION_ARG_1,
d,
f,
$$ACTION_ARG_1
$$ACTION_ARG_2
]));
return [
action2,
registerServerReference("188d5d945750dc32e2c842b93c75a65763d4a922", $$ACTION_1).bind(null, encryptActionBoundArgs("188d5d945750dc32e2c842b93c75a65763d4a922", [
action2,
$$ACTION_ARG_0,
$$ACTION_ARG_1,
d
]))
];
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/build/swc/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ function getBaseSWCOptions({
// TODO: remove this option
enabled: true,
isReactServerLayer,
hashSalt: '',
}
: undefined,
// For app router we prefer to bundle ESM,
Expand Down
20 changes: 17 additions & 3 deletions packages/next/src/build/webpack/loaders/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ import { RSC_MODULE_TYPES } from '../../../shared/lib/constants'
const imageExtensions = ['jpg', 'jpeg', 'png', 'webp', 'avif', 'ico', 'svg']
const imageRegex = new RegExp(`\\.(${imageExtensions.join('|')})$`)

// Determine if the whole module is server action, 'use server' in the top level of module
export function isActionServerLayerEntryModule(mod: {
resource: string
buildInfo?: any
}) {
const rscInfo = mod.buildInfo.rsc
return !!(rscInfo?.actions && rscInfo?.type === RSC_MODULE_TYPES.server)
}

// Determine if the whole module is client action, 'use server' in nested closure in the client module
function isActionClientLayerModule(mod: { resource: string; buildInfo?: any }) {
const rscInfo = mod.buildInfo.rsc
return !!(rscInfo?.actions && rscInfo?.type === RSC_MODULE_TYPES.client)
}

export function isClientComponentEntryModule(mod: {
resource: string
buildInfo?: any
}) {
const rscInfo = mod.buildInfo.rsc
const hasClientDirective = rscInfo?.isClientRef
const isActionLayerEntry =
rscInfo?.actions && rscInfo?.type === RSC_MODULE_TYPES.client
const isActionLayerEntry = isActionClientLayerModule(mod)
return (
hasClientDirective || isActionLayerEntry || imageRegex.test(mod.resource)
)
Expand All @@ -39,7 +53,7 @@ export function isCSSMod(mod: {
)
}

export function getActions(mod: {
export function getActionsFromBuildInfo(mod: {
resource: string
buildInfo?: any
}): undefined | string[] {
Expand Down
Loading
Loading