Skip to content

refactor(hmr): diff css updates from the final emitted asset bytes (emit-hash alternative) - #14951

Draft
stormslowly wants to merge 2 commits into
feat/hmr-precise-css-updatesfrom
feat/hmr-css-emit-asset-hash
Draft

refactor(hmr): diff css updates from the final emitted asset bytes (emit-hash alternative)#14951
stormslowly wants to merge 2 commits into
feat/hmr-precise-css-updatesfrom
feat/hmr-css-emit-asset-hash

Conversation

@stormslowly

Copy link
Copy Markdown
Contributor

Why

Side-by-side comparison for #14682: two candidate mechanisms for deciding which chunks enter the hot-update manifest's css.c / miniCss.c. This draft carries the emit-hash approach so reviewers can weigh it against the create-hash approach on the base branch; it is not meant to land as-is — one of the two gets picked.

  • This PR (emit-hash): hash each chunk's final emitted css asset bytes right before assets are written (CompilerEmit), and commit the baseline only after a fully successful emission (CompilerAfterEmit). Every processAssets transform and asset-level operation is covered by the diff — realContentHash-like semantics. Costs: hashing asset bytes on every build (~41µs/MB), the manifest is emitted outside the processAssets pipeline (invisible to processAssets-stage consumers, diverging from webpack), and a staged/commit protocol is needed for failed builds.
  • Base (create-hash, feat(hmr): emit css.c / css.r in the hot-update manifest for precise CSS updates #14682): read the unsalted css-related hashers the css plugins feed into the chunk content_hash hook. Zero extra hashing (the digests are byproducts of hashing the chunk anyway), the manifest stays inside processAssets (webpack parity), and the baseline shares CompilationRecords' lifecycle. Asset-level rewrites after hashing are out of scope — matching how the js side of HMR already ignores processAssets changes.

The two tests unique to this approach encode the semantics only it can provide:

  • e2e css/hmr-css-processed-after-hash — a banner rewriting the stylesheet during processAssets (content keyed on the compilation hash) is still delivered on a js-only edit
  • hotCases/css/css-extract-asset-source-deleted — deleting a css asset's source via the assets proxy is reported as miniCss.r and the stylesheet is removed

Alternative to the create-hash approach: snapshot each chunk's emitted css
asset bytes right before assets are written (CompilerEmit) and commit the
baseline only after a fully successful emission (CompilerAfterEmit), so any
processAssets transform and asset-level operation is covered by the diff.
@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 5 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 552.1 KB - -
react-10k 5.6 MB 1.3 MB - -
react-1k 823.1 KB 217.0 KB - -
react-5k 2.7 MB 663.8 KB - -
ui-components 4.9 MB 1.4 MB - -
📋 Detailed Reports (Click to expand)

📁 popular-libs

Path: ../build-tools-performance/cases/popular-libs/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 1.7 MB - -
🗜️ Gzip Size 552.1 KB - -
📄 JavaScript 1.7 MB - -
🎨 CSS 0 B - -
🌐 HTML 289.0 B - -
📁 Other Assets 0 B - -

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.6 MB - -
🗜️ Gzip Size 1.3 MB - -
📄 JavaScript 5.6 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 823.1 KB - -
🗜️ Gzip Size 217.0 KB - -
📄 JavaScript 822.7 KB - -
🎨 CSS 0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.7 MB - -
🗜️ Gzip Size 663.8 KB - -
📄 JavaScript 2.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 4.9 MB - -
🗜️ Gzip Size 1.4 MB - -
📄 JavaScript 4.8 MB - -
🎨 CSS 112.1 KB - -
🌐 HTML 328.0 B - -
📁 Other Assets 0 B - -

Generated by Rsdoctor GitHub Action

@github-actions

github-actions Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing fe7082d to Merge branch 'main' into feat/hmr-precise-css-updates by pshu

⏳ The base commit triggered a linux binding build, but its binary size data has not been generated yet, so the size comparison is skipped.

Please re-run this workflow once the ecosystem-benchmark data for that commit is published.

Warning

Reference only — not the real baseline. The base commit's data isn't ready yet, so this compares against the nearest earlier commit that has data (c08d155) for a rough estimate:

❌ Size increased by 48.13KB from 66.73MB to 66.78MB (⬆️0.07%)

@codspeed-hq

codspeed-hq Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 46 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing feat/hmr-css-emit-asset-hash (fe7082d) with feat/hmr-precise-css-updates (46e48ec)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: fe7082d
Status: ✅  Deploy successful!
Preview URL: https://ac2f815c.rspack-v2.pages.dev
Branch Preview URL: https://feat-hmr-css-emit-asset-hash.rspack-v2.pages.dev

View logs

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