Skip to content

fix(plugin): resolve crash on invalidate() in plugin mode - #2378

Open
bjohansebas wants to merge 1 commit into
mainfrom
fix-plugin-mode-invalidate
Open

fix(plugin): resolve crash on invalidate() in plugin mode#2378
bjohansebas wants to merge 1 commit into
mainfrom
fix-plugin-mode-invalidate

Conversation

@bjohansebas

@bjohansebas bjohansebas commented Jul 29, 2026

Copy link
Copy Markdown
Member

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.

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 owns watching.

Overview
Fixes a crash when invalidate() is called while webpack-dev-middleware runs as a plugin (isPlugin = true), where the middleware no longer owns a watching instance.

invalidate() now uses the middleware’s own watching when present (standalone usage). In plugin mode it forwards invalidation to the host’s compiler.watching, or to each child compiler’s watching on MultiCompiler when top-level watching is missing (webpack < 5.109). If nothing is watching, it logs a warning instead of throwing—aligned with existing plugin-mode close() 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.

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-bot

changeset-bot Bot commented Jul 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c801900

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
webpack-dev-middleware Patch

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

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.33333% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.44%. Comparing base (ac84095) to head (c801900).

Files with missing lines Patch % Lines
src/index.js 73.33% 3 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

Comment thread src/index.js
filledContext.logger.warn(
"The `invalidate` method was called, but the compiler is not watching, so there is nothing to invalidate.",
);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)
Fix in Cursor Fix in Web

Triggered by learned rule: Plugin mode guards must log warnings, not silently no-op

Reviewed by Cursor Bugbot for commit c801900. Configure here.

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