diff --git a/.changepacks/changepack_log_boa_debug_stack.json b/.changepacks/changepack_log_boa_debug_stack.json new file mode 100644 index 000000000..de9de1a3f --- /dev/null +++ b/.changepacks/changepack_log_boa_debug_stack.json @@ -0,0 +1,7 @@ +{ + "changes": { + "bindings/devup-ui-wasm/package.json": "Patch" + }, + "note": "Test infrastructure: debug and test builds compile Boa (boa_parser, boa_engine, boa_ast) at opt-level 1, so a vanilla-extract stylesheet with a call nested in a chained call, such as `g(f(1)).d(3).toString()`, no longer overflows the 2 MiB stack of a test thread while Boa parses the instrumented stylesheet. Release builds and the published packages are unchanged. No new build errors", + "date": "2026-11-15T00:00:00.000Z" +} diff --git a/Cargo.toml b/Cargo.toml index 824e9553c..1d5260c87 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,3 +63,16 @@ panic = "abort" [profile.native] inherits = "release" opt-level = 3 + +# Boa parses and compiles JavaScript recursively. Unoptimized, its frames are +# large enough that the nesting of an instrumented stylesheet (a call in a +# chained call) overflows the 2 MiB stack of a test thread, so debug and test +# builds optimize Boa. Release builds are unaffected. +[profile.dev.package.boa_parser] +opt-level = 1 + +[profile.dev.package.boa_engine] +opt-level = 1 + +[profile.dev.package.boa_ast] +opt-level = 1 diff --git a/libs/extractor/src/lib.rs b/libs/extractor/src/lib.rs index 71b38efe2..fceed820a 100644 --- a/libs/extractor/src/lib.rs +++ b/libs/extractor/src/lib.rs @@ -129,6 +129,8 @@ mod stylesheet_gate_boundaries_tests; mod stylesheet_policy; #[cfg(test)] mod stylesheet_regression_tests; +#[cfg(test)] +mod stylesheet_stack_tests; mod stylex; mod tailwind; mod tailwind_children; diff --git a/libs/extractor/src/stylesheet_stack_tests.rs b/libs/extractor/src/stylesheet_stack_tests.rs new file mode 100644 index 000000000..ff7eaed57 --- /dev/null +++ b/libs/extractor/src/stylesheet_stack_tests.rs @@ -0,0 +1,49 @@ +use crate::{ExtractOption, ExtractStyleValue, ImportAlias, extract}; +use css::{class_map::reset_class_map, file_map::reset_file_map}; +use rstest::rstest; +use serial_test::serial; +use std::collections::HashMap; + +/// A stylesheet is instrumented before Boa runs it, so each authored call nests +/// a few more expressions; Boa parses and compiles them recursively. This runs on +/// the 2 MiB stack every test thread gets, which unoptimized Boa overflowed. +#[rstest] +#[case::nested_chain("g(f(1)).d(3).toString()", "4px")] +#[case::deeper_argument("g(f(f(f(1)))).d(3).toString()", "4px")] +#[case::chain_in_chain("g(g(f(1)).d(2).toString()).d(3).toString()", "6px")] +#[case::three_chains( + "g(g(g(f(f(1))).d(2).toString()).d(2).toString()).d(3).toString()", + "8px" +)] +#[serial] +fn nested_chained_call_fits_the_test_thread_stack(#[case] width: &str, #[case] expected: &str) { + // Given: a vanilla-extract stylesheet reading a call nested in a chained call. + reset_class_map(); + reset_file_map(); + let code = format!( + "import {{ style }} from '@vanilla-extract/css';\nconst f = (x) => x;\nconst g = (x) => ({{ d: (y) => ({{ toString: () => `${{Number.parseInt(`${{x}}`, 10) + y}}px` }}) }});\nexport const a = style({{ width: {width} }});" + ); + let option = ExtractOption { + import_aliases: HashMap::from([( + "@vanilla-extract/css".to_string(), + ImportAlias::NamedToNamed, + )]), + ..ExtractOption::default() + }; + + // When + let output = extract("/src/a.css.ts", &code, option).map_err(|error| error.to_string()); + + // Then: it is evaluated to the width it computes. + let widths: Vec = output + .iter() + .flat_map(|output| &output.styles) + .filter_map(|style| match style { + ExtractStyleValue::Static(style) if style.property == "width" => { + Some(style.value.clone()) + } + _ => None, + }) + .collect(); + assert_eq!(widths, [expected], "{output:?}"); +}