Skip to content
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
7 changes: 7 additions & 0 deletions .changepacks/changepack_log_boa_debug_stack.json
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions libs/extractor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 49 additions & 0 deletions libs/extractor/src/stylesheet_stack_tests.rs
Original file line number Diff line number Diff line change
@@ -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<String> = 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:?}");
}
Loading