Skip to content

feat: implement compilation.hooks.shouldRecord for NoEmitOnErrorsPlugin#13630

Open
stormslowly wants to merge 8 commits intomainfrom
feat/should-record-hook
Open

feat: implement compilation.hooks.shouldRecord for NoEmitOnErrorsPlugin#13630
stormslowly wants to merge 8 commits intomainfrom
feat/should-record-hook

Conversation

@stormslowly
Copy link
Copy Markdown
Contributor

@stormslowly stormslowly commented Apr 7, 2026

Summary

  • Implement compilation.hooks.shouldRecord (SyncBailHook) to align with webpack behavior
  • NoEmitOnErrorsPlugin now taps shouldRecord to skip recording compilation state when errors are present
  • When shouldRecord returns false, the next HMR rebuild uses records from the last successful compilation (cached via Arc), instead of the errored one
  • Add two HMR e2e test cases with emitOnErrors: false:
    • no-emit-on-errors-recover: normal → error → fix
    • no-emit-on-errors-recover-consecutive: normal → error → error → fix

Related: DigitecGalaxus/next-yak#508 — when emitOnErrors: false , the compiler records the records, but no HMR assets are generated, next round HMR will encounter no HMR asset 404 error resulting a full page reload.

…mitOnErrorsPlugin

Align with webpack's `shouldRecord` hook behavior so that `NoEmitOnErrorsPlugin`
(`emitOnErrors: false`) skips recording compilation state when errors are present.
This ensures the next HMR rebuild compares against the last successful compilation
rather than the errored one, fixing broken HMR recovery after compilation errors.

Closes: DigitecGalaxus/next-yak#508
@stormslowly stormslowly requested a review from hardfist as a code owner April 7, 2026 08:51
Copilot AI review requested due to automatic review settings April 7, 2026 08:51
@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Apr 7, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 16520be666

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 7, 2026

Merging this PR will degrade performance by 3.04%

❌ 3 regressed benchmarks
✅ 25 untouched benchmarks
⏩ 10 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@persistent_cache_restore_after_single_file_change@basic-react-development 28.2 ms 28.6 ms -1.38%
Simulation rust@create_chunk_ids 10.6 ms 10.9 ms -3.04%
Simulation rust@persistent_cache_restore@basic-react-development 26.4 ms 26.9 ms -1.94%

Comparing feat/should-record-hook (207b901) with main (2e0d7a3)

Open in CodSpeed

Footnotes

  1. 10 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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aligns rspack’s “records” behavior with webpack when emitOnErrors: false, preventing errored compilations from overwriting the record baseline used by subsequent HMR rebuilds.

Changes:

  • Added a shouldRecord / should_record compilation hook and used it to decide whether to record compilation state.
  • Updated rebuild record handling to cache last successful CompilationRecords via Arc and reuse it after errored builds.
  • Added two HMR e2e recovery cases covering error → fix and consecutive errors → fix with emitOnErrors: false.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover/rspack.config.js Enables optimization.emitOnErrors: false for the new recovery case
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover/index.js HMR scenario test (normal → error → fix)
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover/errors1.js Expected parse error matcher for the error step
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover/a.js Stepwise source mutations to trigger error then recover
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/rspack.config.js Enables optimization.emitOnErrors: false for consecutive-error recovery case
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/index.js HMR scenario test (normal → error → error → fix)
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/errors1.js Expected parse error matcher for the first error step
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/errors2.js Expected parse error matcher for the second error step
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/a.js Stepwise source mutations to trigger consecutive errors then recover
packages/rspack/src/Compilation.ts Adds compilation.hooks.shouldRecord to the JS hook surface
crates/rspack_plugin_no_emit_on_errors/src/lib.rs Taps the new CompilationShouldRecord hook to disable recording when errors exist
crates/rspack_plugin_hmr/src/lib.rs Adjusts to Compilation.records now being Option<Arc<CompilationRecords>>
crates/rspack_core/src/compiler/rebuild.rs Implements “record only if should_record” + last-successful record caching
crates/rspack_core/src/compiler/mod.rs Adds last_records cache on Compiler
crates/rspack_core/src/compilation/mod.rs Adds CompilationShouldRecord hook and updates records storage to Arc

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB 0
react-10k 5.7 MB 0
react-1k 826.2 KB 0
react-5k 2.7 MB 0
rome 984.1 KB 0
ui-components 4.9 MB 0

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

📦 Binary Size-limit

Comparing 207b901 to fix(cli): disable hmr in preview (#13669) by neverland

❌ Size increased by 5.16KB from 49.36MB to 49.37MB (⬆️0.01%)

stormslowly and others added 4 commits April 7, 2026 18:07
Wire up CompilationShouldRecord through the napi binding layer so that
JS plugins tapping compilation.hooks.shouldRecord are observed by Rust.
Replace hotCases unit tests with Playwright e2e tests that verify the full
dev-server HMR recovery flow with emitOnErrors: false, including error
overlay visibility and page content after recovery.
…ith NoEmitOnErrorsPlugin

fix clippy: remove redundant &
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 8, 2026

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 207b901
Status: ✅  Deploy successful!
Preview URL: https://eebbf0fb.rspack-v2.pages.dev
Branch Preview URL: https://feat-should-record-hook.rspack-v2.pages.dev

View logs

@stormslowly stormslowly enabled auto-merge (squash) April 9, 2026 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants