Skip to content

fix(sheet): ship the license banner once and add a licenseBanner option - #987

Open
owjs3901 wants to merge 4 commits into
mainfrom
fix/css-empty-base-banner
Open

owjs3901 wants to merge 4 commits into
mainfrom
fix/css-empty-base-banner

Conversation

@owjs3901

Copy link
Copy Markdown
Contributor

Summary

A benchmark investigation (webpack, per-file mode, Next fixture benchmark/next-devup-ui, 494 B of CSS) found two wasted pieces of output, and the owner asked for an option to turn the banner off.

1. The banner shipped twice

  • Cause: with no base rules, the shared base devup-ui.css still held the 68 B license banner. Every per-file sheet (devup-ui-23.css) @imports it, so the banner appeared twice in one stylesheet chain. Minifiers keep /*! comments.
  • Fix: StyleSheet::create_css now emits a sheet with no rules as an empty string, banner included (without_bare_header). The base file is still written, so the injected and @imported paths keep resolving (Turbopack devup-ui.css?fileNum=N, Vite/Bun import 'devup-ui.css', HMR rewrites, the webpack stale-pass checks).
  • Why the @import is kept: dropping it when the base is empty is not safe. A per-file sheet can be built before a later module adds base rules, for example the Turbopack coordinator waits only for its own bucket, and that sheet would never pull the base in. Bundlers resolve and inline the @import (css-loader, Lightning CSS), so it costs no shipped bytes. Once the base file is empty, nothing is duplicated.

2. v1.0.83, had a trailing comma

  • Cause: libs/sheet/src/lib.rs read the version by splitting the "version": "1.0.83", line on :, which kept the JSON comma.
  • Fix: package_version parses the manifest with serde_json, which the crate already depends on. The source stays bindings/devup-ui-wasm/package.json, because the published npm version lives there; the Cargo crates are all 0.1.0, so CARGO_PKG_VERSION would be wrong. Both engines build this crate and therefore share the banner. The docs and READMEs that quoted v1.0.82, were corrected.

3. New licenseBanner option (default true)

  • Plugins: licenseBanner?: boolean sits on DevupUIBasePluginOptions next to prefix/singleCss and is threaded into Vite, webpack, Next (webpack via DevupUIWebpackPlugin, Turbopack via the coordinator process; part of the production setup handoff key), Rsbuild and Bun.
  • Engines: the new setLicenseBanner(enabled) / isLicenseBanner() exports exist in both NAPI (bindings/devup-ui-binding: src/lib.rs, adapter.cjs, index.mjs, index.d.cts, argument validation) and WASM. The flag lives in css::license_banner, mirroring debug. The TestStateGuard restores it.
  • Cache: the serialized-CSS cache (perf(binding): reuse a serialized sheet until it changes #967) adds the flag to its key, so a sheet cached with the banner is never served without it.
  • ABI counts: the WASM export count goes 30 → 32 (script.js), the compiler facade 29 → 31, and argument validation 46 → 47 positions, 19 → 20 functions and 272 → 276 cases. The e2e host and validation export lists are updated.
  • Benchmarks: all 13 Devup UI benchmark apps set licenseBanner: false. That covers every benchmark/*devup-ui*/next.config.*, including the turbo, wasm, single, collapse and hybrid stylex/tailwind/vanilla-extract variants, plus vinext-devup-ui/vite.config.ts. Page content is untouched.
  • Docs: each plugin README, the WASM README and AGENTS.md, and the landing installation page (en/ko) now describe the option.

Byte effect on benchmark/next-devup-ui (per-file, 494 B total = 68 B base + 426 B devup-ui-23.css)

Computed from the emitted bytes; no full Next builds were run. The banner is 68 B before the fix and 67 B after (no comma).

base devup-ui.css devup-ui-23.css total
before 68 B (banner only) 426 B 494 B
after, default (licenseBanner on) 0 B 425 B 425 B (−69 B, −14%)
after, licenseBanner: false (benchmark config) 0 B 358 B 358 B (−136 B, −27.5%)

singleCss (benchmark/next-devup-ui-single, one sheet): −1 B by default (comma), −68 B with licenseBanner: false.

Snapshot / test changes

  • The insta snapshots are unchanged. Two assertions that pinned the old behaviour were updated:
    • libs/sheet test_create_css_with_global_selector: after rm_global_css the sheet is empty, so the output is now "" rather than a bare banner. An explicit assert_eq!(…, "") was added, and the snapshot ("") still matches through unwrap_or_default().
    • The global-sheet checks in the libs/sheet and devup-ui-wasm test_code_extract helper: an empty sheet now equals "", not create_header().
  • New tests:
    • package_version cases: valid, pretty-printed, missing, non-string, invalid JSON.
    • The header has no comma; license_header(true/false).
    • without_bare_header.
    • Banner on/off/default through create_css, including that the per-file @import stays.
    • The cache-key test.
    • WASM test_license_banner.
    • wasm-abi banner on/off/default.
    • Per-plugin tests for default, true and false: Vite, webpack, Rsbuild, Next Turbopack, Next webpack forwarding, and Bun with the real WASM engine.

Test plan

  • cargo test -j 2 --workspace (with CARGO_TARGET_DIR set): all green except 3 extractor snapshots that already fail on main. These are styled_computed_tag_tests::computed_tag_keeps_the_numbers_emotion_reads_as_pixels and styled_theme_prop_tests cases 5 and 6. fix(extractor): mark compiled styled components for isStyledComponent #958 added the __devupStyled wrapper without updating these snapshots. This PR does not touch extractor code.
  • cargo clippy --all-targets -- -D warnings, cargo fmt
  • bun test --coverage (root): 6867 pass, 0 fail, 100% lines/functions
  • bun --config=./bunfig.vite.toml test --coverage: plugin.ts 100%. serve-coherence-prereq-native (theme/alias) fails locally only because the temp path is an 8.3 short name (DEVFIV~1) that never matches the long id. That is environment-specific and unrelated to this change.
  • WASM bun run build (export-count gate) and native node build.mjs --target x86_64-pc-windows-msvc
  • e2e/binding/identity.mjs PASS; e2e/binding/validation.mjs: 276 cases, 47 positions, 0 failed
  • NAPI vs WASM byte parity for getCss with the banner on, off and on an empty sheet: identical
  • tsc through each package build; prettier --check on the changed files (README.md, README_ko.md, libs/extractor/README.md and bindings/devup-ui-wasm/AGENTS.md were already unformatted on main)

요약

벤치마크 조사에서 낭비되는 CSS 출력 두 가지가 확인됐습니다. 조사 대상은 webpack 파일별 모드의 Next 픽스처 benchmark/next-devup-ui(CSS 494 B)입니다. 오너 결정에 따라 배너를 끄는 옵션도 추가합니다.

1. 배너가 두 번 실림

  • 원인: 베이스 규칙이 없어도 공유 베이스 devup-ui.css에 68 B 라이선스 배너만 남았습니다. 모든 파일별 시트(devup-ui-23.css)가 이 파일을 @import하므로, 한 스타일시트 체인에 배너가 두 번 들어갔습니다. 압축기는 /*! 주석을 남깁니다.
  • 수정: 규칙이 없는 시트는 이제 배너까지 포함해 빈 문자열로 내보냅니다(without_bare_header). 베이스 파일은 계속 쓰므로 주입된 import와 @import 경로는 그대로 해석됩니다. 해당 경로는 Turbopack ?fileNum=N, Vite/Bun의 import 'devup-ui.css', HMR, webpack stale pass입니다.
  • @import를 유지하는 이유: 베이스가 비었을 때 @import를 빼는 것은 안전하지 않습니다. 이후 모듈이 베이스 규칙을 추가하기 전에 파일별 시트가 만들어질 수 있고(예: Turbopack 코디네이터는 자기 버킷만 기다림), 그 시트는 베이스를 다시 가져오지 않습니다. 번들러가 @import를 인라인하므로 실제로 전송되는 바이트는 없고, 베이스가 비어 있으면 중복도 없습니다.

2. v1.0.83, 뒤의 쉼표

  • 원인: package.json 줄을 :로 나눠 읽어 JSON 쉼표가 남았습니다.
  • 수정: serde_json으로 매니페스트를 파싱합니다. 버전 출처는 npm 버전이 있는 bindings/devup-ui-wasm/package.json 그대로입니다. Cargo 크레이트는 모두 0.1.0이라 CARGO_PKG_VERSION은 맞지 않습니다. 두 엔진이 같은 크레이트를 빌드하므로 배너도 같습니다. v1.0.82,를 인용하던 문서도 고쳤습니다.

3. 새 licenseBanner 옵션 (기본값 true)

  • 플러그인: DevupUIBasePluginOptions에 추가해 Vite, webpack, Next(webpack 및 Turbopack 코디네이터), Rsbuild, Bun에 전달합니다.
  • 엔진: NAPI와 WASM 모두에 setLicenseBanner(enabled) / isLicenseBanner()를 추가했습니다.
  • 캐시: 직렬화 CSS 캐시 키에 이 플래그를 포함합니다.
  • ABI 카운트: WASM export 30 → 32, 컴파일러 facade 29 → 31, 인자 검증은 47개 위치, 20개 함수, 276개 케이스로 갱신했습니다.
  • 벤치마크: Devup UI 벤치마크 앱 13개 설정에 모두 licenseBanner: false를 넣었습니다(페이지 내용은 건드리지 않음).
  • 문서: 플러그인 README, WASM README, 랜딩 설치 페이지(en/ko)에 옵션을 문서화했습니다.

바이트 효과 (benchmark/next-devup-ui, 파일별 모드)

  • 변경 전: 494 B (베이스 68 B + 파일별 426 B)
  • 기본값: 425 B (−69 B, −14%)
  • licenseBanner: false: 358 B (−136 B, −27.5%)
  • singleCss: 기본 −1 B, 배너 끔 −68 B

전체 Next 빌드 없이 출력 바이트로 계산했습니다.

스냅샷 / 테스트

  • insta 스냅샷 파일은 바뀌지 않았습니다. 빈 시트가 배너가 아니라 ""가 된다는 점을 반영해 단언 두 곳을 고쳤습니다.
  • 새 테스트는 버전 파싱, 쉼표 없는 헤더, 빈 시트, 배너 on/off/기본값, 캐시 키, 플러그인별 on/off/기본값을 다룹니다.

테스트 계획

  • cargo test -j 2 --workspace, cargo clippy --all-targets -- -D warnings, cargo fmt. main에서 이미 실패하는 extractor 스냅샷 3개는 예외입니다. #958이 __devupStyled 래퍼를 추가하면서 스냅샷을 갱신하지 않았고, 이 PR은 extractor 코드를 건드리지 않습니다.
  • 루트 bun test --coverage: 6867 통과, 0 실패, 커버리지 100%
  • Vite 테스트 커버리지 100%. serve-coherence-prereq-native는 로컬 8.3 단축 경로(DEVFIV~1) 문제로만 실패하며 이번 변경과 무관합니다.
  • WASM/네이티브 빌드, e2e/binding identity PASS, validation 276 케이스 0 실패
  • NAPI와 WASM의 getCss 출력이 바이트 단위로 동일함을 확인
  • 패키지 빌드를 통한 tsc, 변경 파일 prettier --check

🤖 Generated with Claude Code

owjs3901 and others added 2 commits November 17, 2026 13:08
A stylesheet without any rule is now emitted empty instead of as a bare
license banner. The shared base devup-ui.css of a per-file build with no
base rules held only the banner, and every per-file sheet @imports it, so
the banner shipped twice in one stylesheet chain. The @import itself is
kept: a per-file sheet can be produced before a later module adds base
rules, and bundlers inline the import anyway.

The banner version was read by splitting a package.json line on ':' and
kept the JSON comma (v1.0.83,). It is now parsed from the manifest
(@devup-ui/wasm's npm version; the Cargo crates stay at 0.1.0).

The banner stays on by default. A new licenseBanner plugin option (vite,
webpack, next for webpack and Turbopack, rsbuild, bun) turns it off through
the new setLicenseBanner/isLicenseBanner engine functions, identical in the
NAPI and WASM engines. The serialized-CSS cache keys on the setting. The
Devup UI benchmark apps turn it off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Thread licenseBanner through the Next options next to #918's debug, and set
it with setDebug after restoreSessionState so a dropped state cannot undo it.
Keep the Bun licenseBanner option beside #925's include.

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

codecov Bot commented Nov 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
bindings/devup-ui-binding/index.mjs 100.00% <100.00%> (ø)
bindings/devup-ui-binding/src/lib.rs 100.00% <ø> (ø)
bindings/devup-ui-wasm/src/lib.rs 100.00% <ø> (ø)
libs/binding/src/css_cache.rs 100.00% <100.00%> (ø)
libs/binding/src/lib.rs 100.00% <ø> (ø)
libs/css/src/lib.rs 100.00% <ø> (ø)
libs/css/src/license_banner.rs 100.00% <100.00%> (ø)
libs/css/src/test_state.rs 100.00% <100.00%> (ø)
libs/sheet/src/lib.rs 100.00% <100.00%> (ø)
packages/bun-plugin/src/plugin.ts 100.00% <100.00%> (ø)
... and 5 more
🚀 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 17, 2026 15:55
…umer

setLicenseBanner and isLicenseBanner bring the native package to 32 exported
functions; the consumer e2e still expected 30.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#963 keeps the CSS state of an engine session in CssState; carry the license
banner there too (stored inverted so a fresh session keeps it on), so the
test guard and session swaps restore it. #990 counts 46 validated argument
positions; setLicenseBanner.enabled makes 47. Set the banner next to #962's
project-root setup in Rsbuild and Bun, keep both README sections, and pass
#928's inputs Set in #962's webpack project-root assertion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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