Skip to content

Commit

Permalink
Merge branch 'canary' into 10-21-Remove_printing_fixed_issues_for_Tur…
Browse files Browse the repository at this point in the history
…bopack
  • Loading branch information
kodiakhq[bot] authored Oct 21, 2023
2 parents fad0a1c + a383b93 commit 73374d5
Show file tree
Hide file tree
Showing 67 changed files with 903 additions and 246 deletions.
1 change: 1 addition & 0 deletions .github/workflows/update_fonts_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ env:
jobs:
create-pull-request:
runs-on: ubuntu-latest
if: github.repository_owner == 'vercel'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

189 changes: 176 additions & 13 deletions packages/next-swc/crates/core/src/server_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,16 +283,75 @@ impl<C: Comments> ServerActions<C> {

// export const $ACTION_myAction = async () => {}
let mut new_params: Vec<Pat> = vec![];
let mut new_body: BlockStmtOrExpr = *a.body.clone();

for i in 0..ids_from_closure.len() {
if !ids_from_closure.is_empty() {
// First argument is the encrypted closure variables
new_params.push(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(),
Ident::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into(),
));

// Also prepend the decryption decl into the body.
// var [arg1, arg2, arg3] = await decryptActionBoundArgs(actionId,
// $$ACTION_CLOSURE_BOUND)
let mut pats = vec![];
for i in 0..ids_from_closure.len() {
pats.push(Some(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(),
)));
}
let decryption_decl = VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Array(ArrayPat {
span: DUMMY_SP,
elems: pats,
optional: false,
type_ann: None,
}),
init: Some(Box::new(Expr::Await(AwaitExpr {
span: DUMMY_SP,
arg: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: quote_ident!("decryptActionBoundArgs").as_callee(),
args: vec![
generate_action_id(&self.file_name, &export_name).as_arg(),
quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(),
],
type_args: None,
})),
}))),
definite: Default::default(),
}],
};

match &mut new_body {
BlockStmtOrExpr::BlockStmt(body) => {
body.stmts.insert(0, decryption_decl.into());
}
BlockStmtOrExpr::Expr(body_expr) => {
new_body = BlockStmtOrExpr::BlockStmt(BlockStmt {
span: DUMMY_SP,
stmts: vec![
decryption_decl.into(),
Stmt::Return(ReturnStmt {
span: DUMMY_SP,
arg: Some(body_expr.take()),
}),
],
});
}
}
}

for p in a.params.iter() {
new_params.push(p.clone());
}

// Create the action export decl
self.extra_items
.push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
span: DUMMY_SP,
Expand All @@ -302,9 +361,10 @@ impl<C: Comments> ServerActions<C> {
declare: Default::default(),
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: action_ident.into(),
name: action_ident.clone().into(),
init: Some(Box::new(Expr::Arrow(ArrowExpr {
params: new_params,
body: Box::new(new_body),
..a.clone()
}))),
definite: Default::default(),
Expand Down Expand Up @@ -393,17 +453,64 @@ impl<C: Comments> ServerActions<C> {

// export async function $ACTION_myAction () {}
let mut new_params: Vec<Param> = vec![];
let mut new_body: Option<BlockStmt> = f.body.clone();

// add params from closure collected ids
for i in 0..ids_from_closure.len() {
if !ids_from_closure.is_empty() {
// First argument is the encrypted closure variables
new_params.push(Param {
span: DUMMY_SP,
decorators: vec![],
pat: Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(),
),
pat: Pat::Ident(Ident::new("$$ACTION_CLOSURE_BOUND".into(), DUMMY_SP).into()),
});

// Also prepend the decryption decl into the body.
// var [arg1, arg2, arg3] = await decryptActionBoundArgs(actionId,
// $$ACTION_CLOSURE_BOUND)
let mut pats = vec![];
for i in 0..ids_from_closure.len() {
pats.push(Some(Pat::Ident(
Ident::new(format!("$$ACTION_ARG_{}", i).into(), DUMMY_SP).into(),
)));
}
let decryption_decl = VarDecl {
span: DUMMY_SP,
kind: VarDeclKind::Var,
declare: false,
decls: vec![VarDeclarator {
span: DUMMY_SP,
name: Pat::Array(ArrayPat {
span: DUMMY_SP,
elems: pats,
optional: false,
type_ann: None,
}),
init: Some(Box::new(Expr::Await(AwaitExpr {
span: DUMMY_SP,
arg: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: quote_ident!("decryptActionBoundArgs").as_callee(),
args: vec![
generate_action_id(&self.file_name, &export_name).as_arg(),
quote_ident!("$$ACTION_CLOSURE_BOUND").as_arg(),
],
type_args: None,
})),
}))),
definite: Default::default(),
}],
};

if let Some(body) = &mut new_body {
body.stmts.insert(0, decryption_decl.into());
} else {
new_body = Some(BlockStmt {
span: DUMMY_SP,
stmts: vec![decryption_decl.into()],
});
}
}

for p in f.params.iter() {
new_params.push(p.clone());
}
Expand All @@ -412,9 +519,10 @@ impl<C: Comments> ServerActions<C> {
.push(ModuleItem::ModuleDecl(ModuleDecl::ExportDecl(ExportDecl {
span: DUMMY_SP,
decl: FnDecl {
ident: action_ident,
ident: action_ident.clone(),
function: Box::new(Function {
params: new_params,
body: new_body,
..*f.take()
}),
declare: Default::default(),
Expand Down Expand Up @@ -1109,8 +1217,42 @@ impl<C: Comments> VisitMut for ServerActions<C> {
type_only: false,
with: None,
})));
// Make it the first item
new.rotate_right(1);

// Encryption and decryption only happens on the server layer.
if self.config.is_server {
// import { encryptActionBoundArgs, decryptActionBoundArgs } from
// 'private-next-rsc-action-encryption'
new.push(ModuleItem::ModuleDecl(ModuleDecl::Import(ImportDecl {
span: DUMMY_SP,
specifiers: vec![
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: quote_ident!("encryptActionBoundArgs"),
imported: None,
is_type_only: false,
}),
ImportSpecifier::Named(ImportNamedSpecifier {
span: DUMMY_SP,
local: quote_ident!("decryptActionBoundArgs"),
imported: None,
is_type_only: false,
}),
],
src: Box::new(Str {
span: DUMMY_SP,
value: "private-next-rsc-action-encryption".into(),
raw: None,
}),
type_only: false,
with: None,
})));

// Make it the first item
new.rotate_right(2);
} else {
// Make it the first item
new.rotate_right(1);
}
}

*stmts = new;
Expand Down Expand Up @@ -1215,13 +1357,14 @@ fn annotate_ident_as_action(
) {
// Add the proxy wrapper call `createActionProxy($$id, $$bound, myAction,
// maybe_orig_action)`.
let action_id = generate_action_id(file_name, &export_name);
let mut args = vec![
// $$id
ExprOrSpread {
spread: None,
expr: Box::new(generate_action_id(file_name, &export_name).into()),
expr: Box::new(action_id.clone().into()),
},
// myAction.$$bound = [arg1, arg2, arg3];
// myAction.$$bound = [encryptActionBoundArgs(actionId, [arg1, arg2, arg3])];
// or myAction.$$bound = null; if there are no bound values.
ExprOrSpread {
spread: None,
Expand All @@ -1230,7 +1373,27 @@ fn annotate_ident_as_action(
} else {
ArrayLit {
span: DUMMY_SP,
elems: bound,
elems: vec![Some(ExprOrSpread {
spread: None,
expr: Box::new(Expr::Call(CallExpr {
span: DUMMY_SP,
callee: quote_ident!("encryptActionBoundArgs").as_callee(),
args: vec![
ExprOrSpread {
spread: None,
expr: Box::new(action_id.into()),
},
ExprOrSpread {
spread: None,
expr: Box::new(Expr::Array(ArrayLit {
span: DUMMY_SP,
elems: bound,
})),
},
],
type_args: None,
})),
})],
}
.into()
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* __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";
/* __next_internal_client_entry_do_not_use__ default auto */ /* __next_internal_action_entry_do_not_use__ {"6d53ce510b2e36499b8f56038817b9bad86cabb4":"$$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));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ foo */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export function foo() {}
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ bar */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
'use strict';
export function bar() {}
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ x */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"b78c261f135a7a852508c2920bd7228020ff4bd7":"x"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export const x = 1;
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default class Component {
render() {
return null;
}
render() {
return null;
}
}
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export * from 'foo';
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
export default (()=>{});
import { ensureServerEntryExports } from "private-next-rsc-action-validate";
ensureServerEntryExports([]);
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
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;
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* __next_internal_action_entry_do_not_use__ $$ACTION_1 */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"188d5d945750dc32e2c842b93c75a65763d4a922":"$$ACTION_1"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { encryptActionBoundArgs, decryptActionBoundArgs } from "private-next-rsc-action-encryption";
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// app/send.ts
/* __next_internal_action_entry_do_not_use__ myAction,default */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"c18c215a6b7cdc64bf709f3a714ffdef1bf9651d":"default","e10665baac148856374b2789aceb970f66fec33e":"myAction"} */ 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");
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// app/send.ts
/* __next_internal_action_entry_do_not_use__ foo */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ab21efdafbe611287bc25c0462b1e0510d13e48b":"foo"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var foo = createServerReference("ab21efdafbe611287bc25c0462b1e0510d13e48b");

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/* __next_internal_action_entry_do_not_use__ bar */ import { createActionProxy } from "private-next-rsc-action-proxy";
/* __next_internal_action_entry_do_not_use__ {"ac840dcaf5e8197cb02b7f3a43c119b7a770b272":"bar"} */ import { createActionProxy } from "private-next-rsc-action-proxy";
import { createServerReference } from "private-next-rsc-action-client-wrapper";
export var bar = createServerReference("ac840dcaf5e8197cb02b7f3a43c119b7a770b272");
Loading

0 comments on commit 73374d5

Please sign in to comment.