feat: implement compilation.hooks.shouldRecord for NoEmitOnErrorsPlugin#13630
feat: implement compilation.hooks.shouldRecord for NoEmitOnErrorsPlugin#13630stormslowly wants to merge 8 commits intomainfrom
Conversation
…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
There was a problem hiding this comment.
💡 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".
Merging this PR will degrade performance by 3.04%
Performance Changes
Comparing Footnotes
|
There was a problem hiding this comment.
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_recordcompilation hook and used it to decide whether to record compilation state. - Updated rebuild record handling to cache last successful
CompilationRecordsviaArcand 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.
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover/index.js
Outdated
Show resolved
Hide resolved
tests/rspack-test/hotCases/recover/no-emit-on-errors-recover-consecutive/index.js
Outdated
Show resolved
Hide resolved
Rsdoctor Bundle Diff AnalysisFound 6 projects in monorepo, 0 projects with changes. 📊 Quick Summary
Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 5.16KB from 49.36MB to 49.37MB (⬆️0.01%) |
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 &
Deploying rspack with
|
| 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 |
Summary
compilation.hooks.shouldRecord(SyncBailHook) to align with webpack behaviorNoEmitOnErrorsPluginnow tapsshouldRecordto skip recording compilation state when errors are presentshouldRecordreturnsfalse, the next HMR rebuild uses records from the last successful compilation (cached viaArc), instead of the errored oneemitOnErrors: false:no-emit-on-errors-recover: normal → error → fixno-emit-on-errors-recover-consecutive: normal → error → error → fixRelated: 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.