fix(plugin): resolve crash on invalidate() in plugin mode - #2378
fix(plugin): resolve crash on invalidate() in plugin mode#2378bjohansebas wants to merge 1 commit into
Conversation
When used as a plugin the host (webpack-cli, webpack-dev-server, etc.) owns `compiler.watch()`, so `invalidate()` threw because the middleware has no `watching` of its own. Invalidate the host's `watching` instead (each child compiler's one for a `MultiCompiler` on webpack < 5.109) and warn when the compiler is not watching at all. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: c801900 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2378 +/- ##
==========================================
- Coverage 92.73% 92.44% -0.30%
==========================================
Files 3 3
Lines 1005 1019 +14
Branches 312 317 +5
==========================================
+ Hits 932 942 +10
- Misses 65 68 +3
- Partials 8 9 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit c801900. Configure here.
| filledContext.logger.warn( | ||
| "The `invalidate` method was called, but the compiler is not watching, so there is nothing to invalidate.", | ||
| ); | ||
| } |
There was a problem hiding this comment.
Missing callback on invalidate no-op
Medium Severity
The !invalidated guard warns but never invokes the callback, unlike close(). Because middleware.ready already ran, a provided callback can stay queued forever when state is false, so callers waiting on invalidate(callback) hang. This violates the plugin-mode guard pattern that requires warning and completing the callback on no-op paths.
Additional Locations (1)
Triggered by learned rule: Plugin mode guards must log warnings, not silently no-op
Reviewed by Cursor Bugbot for commit c801900. Configure here.


When used as a plugin the host (webpack-cli, webpack-dev-server, etc.) owns
compiler.watch(), soinvalidate()threw because the middleware has nowatchingof its own. Invalidate the host'swatchinginstead (each child compiler's one for aMultiCompileron webpack < 5.109) and warn when the compiler is not watching at all.Summary
What kind of change does this PR introduce?
Did you add tests for your changes?
Does this PR introduce a breaking change?
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Use of AI
Note
Low Risk
Targeted fix to public
invalidate()behavior in plugin mode with tests; standalone path unchanged when middleware ownswatching.Overview
Fixes a crash when
invalidate()is called while webpack-dev-middleware runs as a plugin (isPlugin = true), where the middleware no longer owns awatchinginstance.invalidate()now uses the middleware’s ownwatchingwhen present (standalone usage). In plugin mode it forwards invalidation to the host’scompiler.watching, or to each child compiler’swatchingonMultiCompilerwhen top-levelwatchingis missing (webpack < 5.109). If nothing is watching, it logs a warning instead of throwing—aligned with existing plugin-modeclose()behavior.Plugin-mode tests cover host-owned invalidation and the no-watch warning; a changeset records the patch.
Reviewed by Cursor Bugbot for commit c801900. Bugbot is set up for automated code reviews on this repo. Configure here.