Skip to content

feat: drop component-selector markers no module selects in one-shot production builds - #1027

Merged
owjs3901 merged 19 commits into
mainfrom
feat/cross-file-component-markers
Nov 19, 2026
Merged

owjs3901 merged 19 commits into
mainfrom
feat/cross-file-component-markers

Conversation

@owjs3901

@owjs3901 owjs3901 commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Refs #690. Follow-up to #1009 (merged).

The owner chose option (b): drop a component-selector marker only when the build is certain no module selects it, and never fail the build. If the build is not certain, it keeps every marker and warns, naming each module and the reason. Each reason has its own category, so the cases can be closed one at a time until the stripping can be on everywhere.

How it works

  1. The extractor reports markers. ExtractOutput.component_markers lists the markers a file gives (only those it actually emits) and the markers its selectors select, including markers of components imported from other modules (named, namespace, re-exported, withComponent). The WASM and N-API Output expose these as givenMarkers and selectedMarkers.
  2. The start-of-build scan reports selections. reserveClassSlots now returns the markers the scanned inventory selects (reserve_class_slots_selecting). The scan is the same inventory that already seeds file numbers, so the marker names match the real transforms.
  3. The plugins keep a ledger (ComponentMarkerLedger in plugin-utils). Every transform records what its module gives and selects. Once every module is transformed, plan() decides:
    • no scan → keep every marker, silently
    • a transformed module selects a marker the scan never saw → keep every marker, warn, and mark the process uncertain, so later compilations in the same process keep their markers too
    • otherwise → drop the markers that are given but selected by no module and written by no module (a--b tokens in authored source, or in modules devup did not transform, are never touched)
  4. The output is rewritten.
    • webpack: processAssets at PROCESS_ASSETS_STAGE_OPTIMIZE, through ReplaceSource, so source maps stay correct
    • Vite: renderChunk, which returns a word-boundary source map
    • Only one-shot production builds do this. Dev servers, watch builds and HMR keep every marker.

Warning format

[devup-ui] Kept every component-selector marker in this build: the start-of-build scan did not see these modules select components from other modules.
  - src/routes/Late.tsx [context-module]: loaded through require.context, import.meta.glob or a computed import(); selects a--b
  - virtual:pages [virtual-module]: a virtual module no file backs; selects a--c

Known cases and whether the inventory covers them

Case Category Status
Files under src/, app/, the import closure of static entries, include packages — covered (scanned)
require.context('./dir', recursive, /re/) with literal arguments context-module now covered: the scan follows it (contextImports)
import.meta.glob('./**/*.tsx') / ['/a/*.tsx', '!…'] with literal patterns context-module now covered: the scan follows it
require.context / import.meta.glob with computed arguments, computed import() context-module warn + keep
Virtual modules (virtual:, \0 ids, files that don't exist) virtual-module warn + keep
Files another tool compiles before devup sees them (MDX, Vue, Svelte, Astro; input ≠ file on disk) compiled-source warn + keep
webpack function entry outside-scan warn + keep. The scan cannot call the function: webpack must invoke it exactly once (pinned by an existing test).
Root pages/ / components/ not imported from src/app/entries outside-scan warn + keep. Adding these roots would renumber class slots in existing projects.
A file the scan read but could not extract scan-failed warn + keep
Dev server / --watch / HMR — keep every marker (modules change after their markers are given)
Next.js with webpack (uses the webpack plugin and its loader) — covered: strips like webpack
webpack persistent cache (warm builds restore modules without running the loader) — covered: the loader keeps each report in the module's buildInfo, which the cache restores
Next.js Turbopack, Rsbuild, Bun plugins — keep every marker; their loaders don't report to a ledger yet (follow-up)
Client/SSR/RSC or several compilations in one process — keep from the first uncertain compilation onward. If an earlier compilation already dropped a marker, the warning names it and asks for a rebuild.

Residual risk: a module that selects a component, is missed by the scan, and is compiled only in a different process than the one that dropped the marker. The scan is the shared ground truth across compilations, so this needs a module that no file backs and that is generated only in that other process.

Tests

  • Rust:
    • extraction_lists_the_markers_it_gives_and_selects_by
    • markers_of_imported_components_are_selected_by_the_importer (named and namespace imports)
    • reservation_returns_the_markers_the_inputs_select (wasm)
  • plugin-utils: the ledger, the warning snapshot, unscannedCause, marker edits, the source map, the registry, contextImports and its reservation integration. 100% coverage.
  • webpack-plugin: what the loader reports (context module, outside scan, compiled source, virtual module), asset stripping, foreign-token guard, warning, wiring only for production builds that are not watching. 100% coverage.
  • vite-plugin: chunk stripping with a map, foreign-token guard, warning once, wiring. 100% coverage.
  • Docs: the limitations page (English) and the styled-components migration page (English and Korean). There is no Korean limitations page yet.
  • Also moves #[serial] below the #[case]s in component_selector_markers.rs: rstest only copies the attributes written after the cases onto each case, so the test(extractor): pin that component-selector markers go only where a selector can read them #1009 tests ran concurrently with other tests that reset the shared maps, and flaked locally.
  • The formatJson / benchmark/history.json fix comes from fix(benchmark): fit a last array of exactly 80 columns on one line #1018 (merged in here with a merge commit), so this PR merges cleanly with or after fix(benchmark): fit a last array of exactly 80 columns on one line #1018.

요약

Refs #690. #1009(머지됨)의 후속 작업입니다.

오너가 선택한 (b) 방식입니다. 어느 모듈도 선택하지 않는다고 빌드가 확신할 때만 component-selector marker를 제거하고, 빌드를 실패시키지는 않습니다. 확신하지 못하면 모든 marker를 유지하고, 원인이 된 모듈과 이유를 경고로 남깁니다. 이유는 카테고리별로 나뉘어 있어서, 경우를 하나씩 막아 가다 보면 결국 모든 빌드에서 제거를 켤 수 있습니다.

동작 방식

  1. extractor가 marker를 보고합니다. ExtractOutput.component_markers에 파일이 주는 marker(실제로 출력한 것만)와 selector가 선택하는 marker가 담깁니다. 다른 모듈에서 import한 컴포넌트(named, namespace, re-export, withComponent)의 marker도 포함됩니다. WASM과 N-API Output에서는 givenMarkers, selectedMarkers로 노출됩니다.
  2. 빌드 시작 스캔이 선택 목록을 보고합니다. reserveClassSlots가 스캔한 인벤토리가 선택하는 marker를 반환합니다. 파일 번호를 정하는 인벤토리와 같은 것이라서 marker 이름이 실제 transform과 일치합니다.
  3. 플러그인이 ledger를 가집니다(plugin-utils의 ComponentMarkerLedger). 모든 transform이 자기 모듈이 주고 선택하는 marker를 기록합니다. 모든 모듈의 transform이 끝나면 plan()이 다음과 같이 결정합니다.
    • 스캔이 없으면: 모든 marker를 유지하고, 경고하지 않습니다.
    • 스캔이 보지 못한 marker를 선택하는 모듈이 있으면: 모든 marker를 유지하고 경고합니다. 프로세스를 uncertain으로 표시하므로, 같은 프로세스의 이후 compilation도 marker를 유지합니다.
    • 그 밖의 경우: 주어졌지만 어느 모듈도 선택하지 않고, 어느 모듈도 직접 쓰지 않은 marker를 제거합니다. 직접 작성한 소스나 devup이 transform하지 않은 모듈에 있는 a--b 토큰은 건드리지 않습니다.
  4. 출력을 다시 씁니다.
    • webpack: PROCESS_ASSETS_STAGE_OPTIMIZE의 processAssets에서 ReplaceSource로 처리하므로 source map이 유지됩니다.
    • Vite: renderChunk에서 처리하고, 단어 경계마다 매핑된 source map을 반환합니다.
    • 일회성 production 빌드에서만 동작합니다. dev 서버, watch 빌드, HMR은 모든 marker를 유지합니다.

알려진 경우와 인벤토리 커버 여부

경우 카테고리 상태
src/, app/, static entry의 import closure, include 패키지 — 커버됨
리터럴 인자의 require.context('./dir', recursive, /re/) context-module 이번에 커버: 스캔이 따라갑니다.
리터럴 패턴의 import.meta.glob context-module 이번에 커버
계산된 인자의 require.context / import.meta.glob, 계산된 import() context-module 경고 + 유지
virtual 모듈(virtual:, \0, 디스크에 없는 파일) virtual-module 경고 + 유지
다른 도구가 먼저 컴파일하는 파일(MDX, Vue, Svelte, Astro. 입력이 디스크 내용과 다름) compiled-source 경고 + 유지
webpack 함수형 entry outside-scan 경고 + 유지. webpack이 정확히 한 번만 호출해야 해서(기존 테스트로 고정됨) 스캔이 호출할 수 없습니다.
src/app/entry에서 import되지 않는 루트 pages/ / components/ outside-scan 경고 + 유지. 이 루트를 추가하면 기존 프로젝트의 클래스 슬롯 번호가 바뀝니다.
스캔이 읽었지만 추출에 실패한 파일 scan-failed 경고 + 유지
dev 서버 / --watch / HMR — 모든 marker 유지
Next.js webpack 모드(webpack 플러그인과 그 loader 사용) — 커버됨: webpack과 같이 제거
webpack persistent cache(warm 빌드는 loader 없이 모듈을 복원) — 커버됨: loader가 보고를 모듈의 buildInfo에 남기고, 캐시가 이를 복원
Next.js Turbopack, Rsbuild, Bun 플러그인 — 모든 marker 유지. loader가 아직 ledger에 보고하지 않습니다(후속 작업).
client/SSR/RSC 등 한 프로세스의 여러 compilation — 처음 uncertain이 된 compilation부터 유지합니다. 앞선 compilation이 이미 제거한 marker가 있으면 경고에 그 marker를 적고 재빌드를 안내합니다.

남은 위험: 컴포넌트를 선택하는데 스캔이 놓친 모듈이, marker를 제거한 프로세스와 다른 프로세스에서만 컴파일되는 경우입니다. 스캔이 compilation 간에 공유되는 기준이므로, 이 경우가 생기려면 파일이 없고 그 다른 프로세스에서만 생성되는 모듈이 있어야 합니다.

테스트

  • Rust: extractor의 given/selected 보고(named, namespace import 포함), wasm 예약의 선택 marker 반환
  • plugin-utils, webpack-plugin, vite-plugin: ledger, 경고, 원인 판별, 에셋/청크 제거, foreign 토큰 보호, source map, production이면서 watch가 아닐 때만 연결되는지. 커버리지 100%
  • 문서: limitations 페이지(영어), styled-components 마이그레이션 페이지(영어, 한국어). 한국어 limitations 페이지는 아직 없습니다.
  • component_selector_markers.rs에서 #[serial]을 #[case] 아래로 옮겼습니다. rstest는 case 뒤에 쓴 attribute만 각 case에 복사하므로, #1009의 테스트가 공유 map을 초기화하는 다른 테스트와 동시에 실행되어 로컬에서 간헐적으로 실패했습니다.
  • formatJson / benchmark/history.json 수정은 #1018의 것을 merge commit으로 가져왔습니다. #1018과 함께 또는 그 뒤에 충돌 없이 머지됩니다.

🤖 Generated with Claude Code

owjs3901 and others added 13 commits November 18, 2026 21:03
…selector can read them

A styled component a file keeps to itself and no selector in that file
names can never be selected, so it renders without a marker, also when it
is only extended or given withComponent there. Selected and exported
components keep theirs: a module importing an export may select it, and
per-file compilation cannot yet show that none does. The limitations page
says so.

Refs #690

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ives test.tsx

Another test may number a file between the reset and the extraction, so
the expected classes come from component_marker instead of fixed names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r-marker-when-referenced

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…alization

#1004 and #1007 merged together left globalKeyframes calling style_to_json
without the fallbacks argument #1007 added, so main did not compile.
It now reads the flag from the collector, as keyframes() does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nent-markers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and selects by

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the reservation scan

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
formatJson counted a trailing comma after every array, so an array that
ends its object and fills exactly 80 columns was split over lines while
Prettier keeps it on one. main's refresh wrote such a row
(devup-ui-large-turbo-wasm), and `bun run lint` rejects history.json again.
The comma now counts only when one follows, and history.json is rewritten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-shot production builds

The loader reports what each module gives and selects to the build's ledger.
After the transforms, a production build that is not watching compares them
with the start-of-build scan: if every selecting module was scanned, markers
no module selects (and no untransformed module wrote) leave the script
assets; otherwise every marker stays and a warning names each module the scan
missed and why. The scan also follows require.context and import.meta.glob
calls whose arguments are written out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot production builds

Each transform reports what its module gives and selects; buildStart takes
what the start-of-build scan selects. renderChunk of a production build that
is not watching drops the markers no module selects or wrote, with a source
map, or keeps every marker and warns once which modules the scan missed and
why. Documents the behaviour and the cases that still keep markers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r tests

rstest copies only the attributes written after the cases onto each case,
so #[serial] above them left the cases running alongside each other and
the other tests that reset the shared file and class maps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
owjs3901 and others added 4 commits November 19, 2026 03:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… follows it

formatJson counted a trailing comma after every array, so the last array of
an object, exactly 80 characters wide, was split over lines that Prettier
joins, and `bun run lint` failed on the recorded history.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…from its cache

A warm build restores modules from webpack's persistent cache without running
the loader, so their reports never reached the ledger and the build kept the
markers a cold build dropped. The loader now keeps each report in the
module's buildInfo, which the cache restores, and the plugin reads them back
before it plans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
benchmark-record.js 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/host.rs 100.00% <ø> (ø)
bindings/devup-ui-binding/src/output.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <100.00%> (ø)
bindings/devup-ui-wasm/src/reservation.rs 100.00% <ø> (ø)
libs/binding/src/lib.rs 100.00% <ø> (ø)
libs/binding/src/output.rs 100.00% <ø> (ø)
libs/binding/src/reservation.rs 100.00% <100.00%> (ø)
libs/extractor/src/component_markers.rs 100.00% <100.00%> (ø)
libs/extractor/src/emotion_namespace/output.rs 100.00% <ø> (ø)
... and 15 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

owjs3901 and others added 2 commits November 19, 2026 06:35
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@owjs3901
owjs3901 merged commit 6cbd427 into main Nov 19, 2026
28 checks passed
@owjs3901
owjs3901 deleted the feat/cross-file-component-markers branch November 19, 2026 01:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant