Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
db6957b
test(extractor): pin that component-selector markers go only where a …
owjs3901 Nov 18, 2026
9f8f5f5
test(extractor): read expected markers from the file number the run g…
owjs3901 Nov 18, 2026
766cea7
Merge remote-tracking branch 'origin/main' into fix/component-selecto…
owjs3901 Nov 18, 2026
9afaaa9
fix(extractor): pass the fallback flag to globalKeyframes' style seri…
owjs3901 Nov 18, 2026
949dfda
Merge remote-tracking branch 'origin/main' into feat/cross-file-compo…
owjs3901 Nov 18, 2026
693b167
feat(extractor): list the component-selector markers each file gives …
owjs3901 Nov 18, 2026
c910213
feat(binding): report component-selector markers from transforms and …
owjs3901 Nov 18, 2026
eca1b6a
fix(benchmark): fit a last array of exactly 80 columns on one line
owjs3901 Nov 18, 2026
efc6365
feat(webpack-plugin): drop component markers no module selects in one…
owjs3901 Nov 18, 2026
bd961cb
feat(vite-plugin): drop component markers no module selects in one-sh…
owjs3901 Nov 18, 2026
cc40f5b
Merge remote-tracking branch 'origin/main' into feat/cross-file-compo…
owjs3901 Nov 18, 2026
cb0a0b5
test(binding): read the marker getters in the public engine scenarios
owjs3901 Nov 18, 2026
3bd7109
test(extractor): serialize every case of the component-selector marke…
owjs3901 Nov 18, 2026
f5b9ced
docs: keep the marker rows within the migration tables' width
owjs3901 Nov 18, 2026
2efb345
fix(benchmark): print an array as wide as Prettier does when no comma…
owjs3901 Nov 18, 2026
4b50cfb
fix(webpack-plugin): read marker reports of modules webpack restores …
owjs3901 Nov 18, 2026
bc2855e
docs: say Next.js webpack builds drop unselected markers too
owjs3901 Nov 18, 2026
d4df3c2
revert: leave the formatJson fix to #1018
owjs3901 Nov 18, 2026
6382936
Merge remote-tracking branch 'origin/fix/benchmark-json-last-array' i…
owjs3901 Nov 18, 2026
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
12 changes: 12 additions & 0 deletions .changepacks/changepack_log_cross_file_component_markers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"changes": {
"bindings/devup-ui-wasm/package.json": "Patch",
"bindings/devup-ui-binding/package.json": "Patch",
"packages/plugin-utils/package.json": "Patch",
"packages/webpack-plugin/package.json": "Patch",
"packages/next-plugin/package.json": "Patch",
"packages/vite-plugin/package.json": "Patch"
},
"note": "One-shot production builds with the Vite and webpack plugins (Next.js without Turbopack included) drop the component-selector markers no module selects. Each transform and the start-of-build scan report the markers they give and select; once every module is compiled, a marker no module selects or writes leaves the output chunks. When a module selects a component but the scan never read it (virtual module, a file compiled by another tool such as MDX, require.context / import.meta.glob / computed import(), or a file outside the scanned roots and entries), the build keeps every marker and warns with the module and the reason. The scan now also follows require.context and import.meta.glob calls whose arguments are written out. Warm webpack builds read the reports of modules restored from the persistent cache. Dev servers, watch builds, Turbopack and the Rsbuild and Bun plugins keep every marker.",
"date": "2026-11-19T00:00:00.000Z"
}
2 changes: 1 addition & 1 deletion apps/landing/src/app/(detail)/docs/limitations/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ A dynamic value such as `width` becomes a CSS variable set in `style`, so a comp

## Known limitations

- An exported styled component always carries one short marker class (`a--b`), even when no selector in its own file names it. A module importing it may select it (`${Child} { ... }`) or extend it, and each file is built without knowing which files import it, so the class has to be on the element from the start. Leaving it off needs the whole build to know, before it compiles the component, that no module selects it, which per-file compilation cannot show yet. A styled component the file keeps to itself (not exported) carries a marker only when a selector in that file names it, so a private component that is only rendered or extended there carries none.
- An exported styled component carries one short marker class (`a--b`) when it is compiled, even when no selector in its own file names it. A module importing it may select it (`${Child} { ... }`) or extend it, and each file is built without knowing which files import it, so the class has to be on the element from the start. A one-shot production build with the Vite or webpack plugin (including Next.js without Turbopack) takes it off again once every module is compiled: the start-of-build scan reports what each file it reads selects, each transform reports what its module selects, and a marker that neither lists, and that no module wrote itself, leaves the output chunks. When a module selects a component but the scan never read it (a virtual module; a file another tool compiles first, such as MDX; a file loaded through `require.context`, `import.meta.glob` or a computed `import()` whose arguments the scan cannot read; or a file outside the scanned roots and entries, such as one only a function `entry` reaches), the build keeps every marker and warns, naming each such module and the reason. Dev servers, watch builds, Turbopack and the Rsbuild and Bun plugins keep every marker. A styled component the file keeps to itself (not exported) carries a marker only when a selector in that file names it, so a private component that is only rendered or extended there carries none.
- A class, `keyframes` name or styled component defined in another module is not read as a build-time value: its name is only known once that file is built. Declare it in the file that uses it, or read it from a style prop.
- `css()`, `globalCss()` and `keyframes()` have no element to set a CSS variable on, so a runtime value there is a build error. Move it to a style prop.
- A styled-components or Emotion style function may read the theme only as `theme.a.b` (or `theme.a[2]`). Calls, whole-theme reads and runtime keys are build errors.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ styled 컴포넌트는 함수 컴포넌트로 컴파일되며 React 19는 함수
| `css` prop, `jsx`, JSX runtime pragma | `className`과 `style`로 컴파일됨 |
| `ClassNames` | child가 렌더링하는 결과로 대체되며, 각 `css` / `cx` 호출은 클래스로 컴파일됨 |
| 컴포넌트 선택자(`${Child}`) | marker 클래스. Emotion의 확장 컴포넌트는 Emotion에서처럼 이를 제외하고 렌더링함 |
| 어느 모듈도 선택하지 않는 marker | Vite·webpack 일회성 production 빌드에서 제거됨 |
| `.attrs()`, `.withConfig()` | attrs는 props 위에 병합됨. 빌드 타임 `shouldForwardProp`. `componentId` 클래스 |

## 제한 사항
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ A styled component compiles to a function component, whose `defaultProps` React
| `css` prop, `jsx`, JSX runtime pragmas | compiled to `className` and `style` |
| `ClassNames` | replaced by what its child renders, each `css` / `cx` call compiled to classes |
| Component selectors (`${Child}`) | a marker class; Emotion extensions render without it, as Emotion's do |
| Markers no module selects | dropped by one-shot Vite and webpack production builds |
| `.attrs()`, `.withConfig()` | attrs merged over props; build-time `shouldForwardProp`; `componentId` classes |

## Limitations
Expand Down
5 changes: 3 additions & 2 deletions benchmark-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ export function formatJson(value) {
return (
JSON.stringify(value, null, 2).replace(
/^( *)(.*)\[\n((?:\1 {2}(?:-?[\d.e+-]+|"[^"\n]*"|null),?\n)+)\1\]/gm,
(whole, indent, key, items) => {
(whole, indent, key, items, offset, json) => {
const values = items.trim().split(/,\n */)
const line = `${indent}${key}[${values.join(', ')}]`
if (line.length + 1 <= PRINT_WIDTH) return line
const comma = json[offset + whole.length] === ',' ? 1 : 0
if (line.length + comma <= PRINT_WIDTH) return line
return values.every((item) => /^-?[\d.e+-]+$/.test(item))
? fillNumbers(indent, key, values)
: whole
Expand Down
4 changes: 1 addition & 3 deletions benchmark/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@
"devup-ui-large": [15.099, 15.029, 15.117, 88882994, 1388, 934329],
"devup-ui-large-wasm": [16.233, 16.017, 16.28, 89000421, 1388, 934329],
"devup-ui-large-turbo": [6.037, 5.938, 6.244, 38676786, 1512, 571629],
"devup-ui-large-turbo-wasm": [
6.5, 6.483, 6.542, 38662174, 1512, 571629
]
"devup-ui-large-turbo-wasm": [6.5, 6.483, 6.542, 38662174, 1512, 571629]
}
},
{
Expand Down
6 changes: 5 additions & 1 deletion bindings/devup-ui-binding/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ export class Output {
readonly css: string | undefined
/** Each access returns an independent array; mutating it does not change native state. */
readonly dependencies: string[]
/** Marker classes the source's components render with, for component selectors. */
readonly givenMarkers: string[]
/** Marker classes the source's styles select components by. */
readonly selectedMarkers: string[]
readonly map: string | undefined
readonly updatedBaseStyle: boolean
}
Expand Down Expand Up @@ -80,7 +84,7 @@ export function reserveClassSlots(
importMainCssInCode: boolean,
importMainCssInCss: boolean,
importAliases: unknown,
): void
): string[]
export function resetBuildState(): void
export function resetStateForTesting(): void
export function seedFileMap(files: string[]): void
Expand Down
7 changes: 4 additions & 3 deletions bindings/devup-ui-binding/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub fn reserve<'env>(
callback: AccessCallback<'env>,
schema_token: Unknown<'env>,
access_token: Unknown<'env>,
) -> Result<()> {
) -> Result<Vec<String>> {
let access = Access {
env,
callback,
Expand Down Expand Up @@ -272,7 +272,8 @@ pub fn reserve<'env>(
diagnostics.add_source(&input.filename, &input.code);
}
with_resolver(env, diagnostics, |resolver, _check| {
core::reserve_class_slots_internal(&inputs, option, resolver);
Ok(())
Ok(core::reserve_class_slots_selecting(
&inputs, option, resolver,
))
})
}
10 changes: 10 additions & 0 deletions bindings/devup-ui-binding/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,14 @@ impl NativeOutput {
pub fn dependencies(&self, env: Env) -> Result<Vec<String>> {
Ok(self.live(env)?.dependencies.clone())
}
/// Copy the marker classes the source's components render with.
#[napi(getter, js_name = "givenMarkers")]
pub fn given_markers(&self, env: Env) -> Result<Vec<String>> {
Ok(self.live(env)?.component_markers.given.clone())
}
/// Copy the marker classes the source's styles select components by.
#[napi(getter, js_name = "selectedMarkers")]
pub fn selected_markers(&self, env: Env) -> Result<Vec<String>> {
Ok(self.live(env)?.component_markers.selected.clone())
}
}
17 changes: 17 additions & 0 deletions bindings/devup-ui-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub struct Output {
updated_base_style: bool,
css: Option<binding_core::LazyCss>,
dependencies: Vec<String>,
component_markers: extractor::ComponentMarkers,
}

impl From<binding_core::Output> for Output {
Expand All @@ -69,6 +70,7 @@ impl From<binding_core::Output> for Output {
updated_base_style: output.updated_base_style,
css: output.css,
dependencies: output.dependencies,
component_markers: output.component_markers,
}
}
}
Expand All @@ -94,6 +96,7 @@ impl Output {
map,
css_file,
dependencies,
component_markers: extractor::ComponentMarkers::default(),
},
filename,
binding_core::CssOptions {
Expand Down Expand Up @@ -143,6 +146,20 @@ impl Output {
pub fn dependencies(&self) -> Vec<String> {
self.dependencies.clone()
}

/// Marker classes the source's components render with, for selectors
#[wasm_bindgen(getter, js_name = "givenMarkers")]
#[must_use]
pub fn given_markers(&self) -> Vec<String> {
self.component_markers.given.clone()
}

/// Marker classes the source's styles select components by
#[wasm_bindgen(getter, js_name = "selectedMarkers")]
#[must_use]
pub fn selected_markers(&self) -> Vec<String> {
self.component_markers.selected.clone()
}
}

#[wasm_bindgen(js_name = "setDebug")]
Expand Down
14 changes: 8 additions & 6 deletions bindings/devup-ui-wasm/src/reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use wasm_bindgen::prelude::*;

#[cfg(test)]
use crate::with_style_sheet_mut;
pub use devup_ui_binding_core::{ReservationInput, reserve_class_slots_internal};
pub use devup_ui_binding_core::{
ReservationInput, reserve_class_slots_internal, reserve_class_slots_selecting,
};
mod rows;
#[cfg(not(tarpaulin_include))]
use crate::{
Expand All @@ -17,7 +19,8 @@ use crate::{
#[cfg(not(tarpaulin_include))]
use std::{cell::RefCell, rc::Rc};

/// Reserve `[filename, code, cssDir]` rows using the current resolver and configuration.
/// Reserve `[filename, code, cssDir]` rows using the current resolver and
/// configuration; the component-selector markers the rows' styles select.
#[wasm_bindgen(js_name = "reserveClassSlots")]
#[cfg(not(tarpaulin_include))]
pub fn reserve_class_slots(
Expand All @@ -27,7 +30,7 @@ pub fn reserve_class_slots(
import_main_css_in_code: bool,
_import_main_css_in_css: bool,
import_aliases: JsValue,
) -> Result<(), JsValue> {
) -> Result<Vec<String>, JsValue> {
let rows: Vec<Vec<String>> = const { boundary::wasm() }.decode(rows, 0)?;
let inputs = rows::parse_rows(rows).map_err(|_| boundary::fail(0))?;
let option = ExtractOption {
Expand All @@ -49,14 +52,13 @@ pub fn reserve_class_slots(
call_module_resolver(&resolver, request, &state)
}
});
reserve_class_slots_internal(
Ok(reserve_class_slots_selecting(
&inputs,
option,
resolver
.as_ref()
.map(|resolver| resolver as &ModuleResolver),
);
Ok(())
))
}

/// New live class and file slots since this build's first reservation; repeats do not count.
Expand Down
43 changes: 43 additions & 0 deletions bindings/devup-ui-wasm/src/reservation/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,3 +452,46 @@ fn supplied_physical_order_is_not_resorted_by_engine_id() -> TestResult {
assert_eq!(get_unreserved_class_slot_count(), 0);
Ok(())
}

const CHILD: &str = "import {styled} from '@devup-ui/react'; export const Child = styled.div`color: red;`; export const Other = styled.span`color: blue;`;";
const PARENT: &str = "import {styled} from '@devup-ui/react'; import {Child} from './child'; export const Parent = styled.div`${Child} { color: green; }`;";

fn child_module(specifier: &str, _: &str) -> Option<extractor::ResolvedModule> {
(specifier == "./child").then(|| extractor::ResolvedModule {
path: "child.tsx".into(),
code: CHILD.into(),
})
}

#[test]
#[serial]
fn reservation_returns_the_markers_the_inputs_select() -> TestResult {
// Given
let (_reset, option) = setup(true);
let inputs = [input("child.tsx", CHILD), input("parent.tsx", PARENT)];
// When
let selected = reserve_class_slots_selecting(&inputs, option.clone(), Some(&child_module));
// Then
let child = transform(&inputs[0], &option)?;
let parent = code_extract_with_modules_internal(
"parent.tsx",
PARENT,
&option.package,
"./css".into(),
option.single_css,
option.import_main_css,
true,
option.import_aliases.clone(),
&child_module,
)?;
assert_eq!(selected, parent.selected_markers());
assert_eq!(child.given_markers().len(), 2);
assert!(child.given_markers().contains(&selected[0]));
assert!(
parent
.given_markers()
.iter()
.all(|marker| !selected.contains(marker))
);
Ok(())
}
2 changes: 2 additions & 0 deletions e2e/binding/diagnostics.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ export function runDiagnostics(w) {
'cssFile',
'updatedBaseStyle',
'dependencies',
'givenMarkers',
'selectedMarkers',
'free',
Symbol.dispose,
]) {
Expand Down
2 changes: 2 additions & 0 deletions e2e/binding/host.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ const fields = [
'cssFile',
'updatedBaseStyle',
'dependencies',
'givenMarkers',
'selectedMarkers',
]
const exports4 = [
'exportSheet',
Expand Down
4 changes: 3 additions & 1 deletion libs/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub use css_cache::{SheetCell, SheetGuard};
pub use extractor::{has_devup_ui, has_devup_ui_with};
pub use lazy_css::LazyCss;
pub use output::{CssOptions, ExtractionMode, Output, SourceMapMode, code_extract};
pub use reservation::{ReservationInput, reserve_class_slots_internal};
pub use reservation::{
ReservationInput, reserve_class_slots_internal, reserve_class_slots_selecting,
};
pub use resolver_state::{ResolverRequest, ResolverState, check_resolved_path, resolved_module};
pub use session::{
PerSession, create_session, drop_session, live_session, select_session, with_session,
Expand Down
3 changes: 3 additions & 0 deletions libs/binding/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ pub struct Output {
pub css: Option<LazyCss>,
/// Files read through the module resolver.
pub dependencies: Vec<String>,
/// The component-selector markers the source gives and selects by.
pub component_markers: extractor::ComponentMarkers,
}

impl Output {
Expand Down Expand Up @@ -88,6 +90,7 @@ impl Output {
map: output.map,
css_file: output.css_file,
dependencies: output.dependencies,
component_markers: output.component_markers,
updated_base_style: updated_base_style || default_collected,
css: {
if !collected && !default_collected {
Expand Down
15 changes: 15 additions & 0 deletions libs/binding/src/reservation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ pub fn reserve_class_slots_internal(
option: ExtractOption,
resolver: Option<&ModuleResolver>,
) {
let _ = reserve_class_slots_selecting(inputs, option, resolver);
}

/// [`reserve_class_slots_internal`], returning the component-selector
/// markers the inputs' styles select, sorted, once each: those a build may
/// keep when it drops the markers no module reads.
#[must_use]
pub fn reserve_class_slots_selecting(
inputs: &[ReservationInput],
option: ExtractOption,
resolver: Option<&ModuleResolver>,
) -> Vec<String> {
let mut selected = std::collections::BTreeSet::new();
let _atom_mode = css::atom_hoist::AtomModeGuard::new(option.single_css);
let slots = ScratchSlots::default();
let files: Vec<String> = inputs.iter().map(|input| input.filename.clone()).collect();
Expand All @@ -72,6 +85,7 @@ pub fn reserve_class_slots_internal(
None => extract_without_source_map(&input.filename, &input.code, file_option),
};
if let Ok(output) = extracted {
selected.extend(output.component_markers.selected);
let bucket = file_map::canonical(&input.filename);
let global = option.single_css || file_map::is_global(&input.filename);
with_style_sheet_mut(|sheet| {
Expand All @@ -81,4 +95,5 @@ pub fn reserve_class_slots_internal(
}
}
slots.commit();
selected.into_iter().collect()
}
1 change: 1 addition & 0 deletions libs/extractor/src/class_selection_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub fn observe(outputs: &Modules, observer: &str, globals: &str) -> serde_json::
map: output.map.clone(),
css_file: output.css_file.clone(),
dependencies: output.dependencies.clone(),
component_markers: crate::ComponentMarkers::default(),
},
)
}));
Expand Down
54 changes: 54 additions & 0 deletions libs/extractor/src/component_markers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! The component-selector markers a file gives and the ones its styles read.
//!
//! A styled component carries a marker class when a selector may pick it out
//! (`${Child} { ... }`, `[Child]`): one in its own file, or, as it is
//! exported, one in a module importing it. A build that has seen every
//! module can drop each marker no module's styles read; these lists are what
//! it needs to know which.

/// The marker classes of one extraction
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct ComponentMarkers {
/// Markers the file's components render with, in order, once each
pub given: Vec<String>,
/// Markers the file's styles select a component by, in order, once each
pub selected: Vec<String>,
}

impl ComponentMarkers {
/// Record `marker` as one a component of the file renders with
pub(crate) fn give(&mut self, marker: &str) {
push_once(&mut self.given, marker);
}

/// Record `marker` as one a selector of the file reads
pub(crate) fn select(&mut self, marker: &str) {
push_once(&mut self.selected, marker);
}
}

fn push_once(list: &mut Vec<String>, marker: &str) {
if !list.iter().any(|known| known == marker) {
list.push(marker.to_string());
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn each_marker_is_recorded_once_in_order() {
// Given
let mut markers = ComponentMarkers::default();
// When
markers.give("a--a");
markers.give("a--b");
markers.give("a--a");
markers.select("b--a");
markers.select("b--a");
// Then
assert_eq!(markers.given, ["a--a", "a--b"]);
assert_eq!(markers.selected, ["b--a"]);
}
}
Loading
Loading