Skip to content

Commit 4a5fea2

Browse files
committed
WIP debug
1 parent 257bf8d commit 4a5fea2

File tree

7 files changed

+74
-48
lines changed

7 files changed

+74
-48
lines changed

crates/next-api/src/module_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub struct ServerActionsGraph {
238238
}
239239

240240
#[turbo_tasks::value]
241-
pub struct ServerActionsGraphs(Vec<ResolvedVc<ServerActionsGraph>>);
241+
pub struct ServerActionsGraphs(pub Vec<ResolvedVc<ServerActionsGraph>>);
242242

243243
#[turbo_tasks::value_impl]
244244
impl ServerActionsGraphs {

crates/next-api/src/server_actions.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ async fn parse_actions(module: ResolvedVc<Box<dyn Module>>) -> Result<Vc<OptionA
307307
let fragment = ecmascript_asset.failsafe_parse().resolve().await?;
308308

309309
if fragment != original_parsed {
310+
println!("different {:?}", module.ident_string().await?);
310311
let ParseResult::Ok {
311312
program: fragment, ..
312313
} = &*fragment.await?
@@ -461,6 +462,51 @@ pub async fn map_server_actions(graph: Vc<SingleModuleGraph>) -> Result<Vc<AllMo
461462
// TODO really ignore SSR?
462463
_ => return Ok(None),
463464
};
465+
466+
let id = module.ident_string().await?;
467+
468+
if id.contains("data:") {
469+
println!(
470+
"{:?} {:?} {:#?}",
471+
module.ident_string().await?,
472+
if let Some(v) = &*parse_actions(*module).await? {
473+
Some(v.await?)
474+
} else {
475+
None
476+
},
477+
if let Some(ecmascript_asset) =
478+
ResolvedVc::try_sidecast::<Box<dyn EcmascriptParsable>>(module)
479+
{
480+
(
481+
if let ParseResult::Ok {
482+
program, comments, ..
483+
} = &*ecmascript_asset.parse_original().await?
484+
{
485+
swc_core::ecma::codegen::to_code_with_comments(
486+
Some(&comments.consumable()),
487+
&program,
488+
)
489+
} else {
490+
panic!();
491+
},
492+
if let ParseResult::Ok {
493+
program, comments, ..
494+
} = &*ecmascript_asset.failsafe_parse().await?
495+
{
496+
swc_core::ecma::codegen::to_code_with_comments(
497+
Some(&comments.consumable()),
498+
&program,
499+
)
500+
} else {
501+
panic!();
502+
},
503+
)
504+
} else {
505+
panic!();
506+
}
507+
);
508+
}
509+
464510
// TODO the old implementation did parse_actions(to_rsc_context(module))
465511
// is that really necessary?
466512
Ok(parse_actions(*module)

crates/next-custom-transforms/src/transforms/server_actions.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{
22
cell::RefCell,
3-
collections::{hash_map, BTreeMap},
3+
collections::{BTreeMap, hash_map},
44
convert::{TryFrom, TryInto},
55
mem::{replace, take},
66
path::{Path, PathBuf},
@@ -16,23 +16,23 @@ use rustc_hash::{FxHashMap, FxHashSet};
1616
use serde::Deserialize;
1717
use sha1::{Digest, Sha1};
1818
use swc_core::{
19-
atoms::{atom, Atom},
19+
atoms::{Atom, atom},
2020
common::{
21+
BytePos, DUMMY_SP, FileName, Mark, SourceMap, Span, SyntaxContext,
2122
comments::{Comment, CommentKind, Comments, SingleThreadedComments},
2223
errors::HANDLER,
23-
source_map::{SourceMapGenConfig, PURE_SP},
24+
source_map::{PURE_SP, SourceMapGenConfig},
2425
util::take::Take,
25-
BytePos, FileName, Mark, SourceMap, Span, SyntaxContext, DUMMY_SP,
2626
},
2727
ecma::{
2828
ast::*,
29-
codegen::{self, text_writer::JsWriter, Emitter},
30-
utils::{private_ident, quote_ident, ExprFactory},
31-
visit::{noop_visit_mut_type, visit_mut_pass, VisitMut, VisitMutWith},
29+
codegen::{self, Emitter, text_writer::JsWriter},
30+
utils::{ExprFactory, private_ident, quote_ident},
31+
visit::{VisitMut, VisitMutWith, noop_visit_mut_type, visit_mut_pass},
3232
},
3333
quote,
3434
};
35-
use turbo_rcstr::{rcstr, RcStr};
35+
use turbo_rcstr::{RcStr, rcstr};
3636

3737
use crate::FxIndexMap;
3838

@@ -2089,6 +2089,19 @@ impl<C: Comments> VisitMut for ServerActions<C> {
20892089
.into(),
20902090
},
20912091
);
2092+
stmts.push(ModuleItem::Stmt(Stmt::Expr(ExprStmt {
2093+
span: DUMMY_SP,
2094+
expr: Box::new(Expr::Lit(Lit::Str(
2095+
generate_server_actions_comment(
2096+
&actions,
2097+
match self.mode {
2098+
ServerActionsMode::Webpack => None,
2099+
ServerActionsMode::Turbopack => Some(("", "")),
2100+
},
2101+
)
2102+
.into(),
2103+
))),
2104+
})));
20922105
} else {
20932106
match self.mode {
20942107
ServerActionsMode::Webpack => {
@@ -3289,9 +3302,14 @@ fn emit_error(error_kind: ServerActionsErrorKind) {
32893302
fn program_to_data_url(
32903303
file_name: &str,
32913304
cm: &Arc<SourceMap>,
3292-
body: Vec<ModuleItem>,
3305+
mut body: Vec<ModuleItem>,
32933306
prepend_comment: Comment,
32943307
) -> String {
3308+
body.push(ModuleItem::Stmt(Stmt::Expr(ExprStmt {
3309+
span: DUMMY_SP,
3310+
expr: Box::new(Expr::Lit(Lit::Str(prepend_comment.text.clone().into()))),
3311+
})));
3312+
32953313
let module_span = Span::dummy_with_cmt();
32963314
let comments = SingleThreadedComments::default();
32973315
comments.add_leading(module_span.lo, prepend_comment);
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
'use server'
22

3-
export async function serverComponentAction() {
4-
return 'server-action'
5-
}
6-
73
export async function clientComponentAction() {
84
return 'client-action'
95
}
10-
11-
export async function unusedExportedAction() {
12-
return 'unused-exported-action'
13-
}

test/production/app-dir/actions-tree-shaking/basic/app/inline/page.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

test/production/app-dir/actions-tree-shaking/basic/app/server/page.js

Lines changed: 0 additions & 10 deletions
This file was deleted.

test/production/app-dir/actions-tree-shaking/basic/basic.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@ import {
2020
const actionsRoutesState = await getActionsRoutesStateByRuntime(next)
2121

2222
expect(actionsRoutesState).toMatchObject({
23-
// only one server layer action
24-
'app/server/page': {
25-
rsc: 3,
26-
},
2723
// only one browser layer action
2824
'app/client/page': {
2925
'action-browser': 1,
3026
},
31-
'app/inline/page': {
32-
rsc: 1,
33-
},
3427
})
3528
})
3629
}

0 commit comments

Comments
 (0)