Skip to content

fix: ensure interceptModuleExecution runs before missing module throw#20493

Closed
NihalShinde4933 wants to merge 1 commit intowebpack:mainfrom
NihalShinde4933:fix/intercept-execution-order
Closed

fix: ensure interceptModuleExecution runs before missing module throw#20493
NihalShinde4933 wants to merge 1 commit intowebpack:mainfrom
NihalShinde4933:fix/intercept-execution-order

Conversation

@NihalShinde4933
Copy link

Description

What is the purpose of this pull request?

This PR addresses a regression where the runtime's missing module existence check (enabled by pathinfo) was executing before the interceptModuleExecution hook.

The Problem

When using HMR with frameworks like Next.js, the React Refresh interceptor needs to catch missing modules to perform a graceful page reload. Currently, Webpack throws a hard MODULE_NOT_FOUND error before the interceptor can run.

The Fix

Moved the existence check inside the interceptModuleExecution logic. The runtime now allows interceptors to modify the module factory or handle the error before the default throw fires.

Verification

Added test/RuntimeInterception.unittest.js to verify the order of generated runtime code.

Verified formatting with yarn fmt

Fixes #20475

Before:
PR-WEBPACK-BEFORE

After:
PR-WEBPACK

@changeset-bot
Copy link

changeset-bot bot commented Feb 20, 2026

⚠️ No Changeset found

Latest commit: 4c85b80

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@NihalShinde4933
Copy link
Author

Hi @alexander-akait 👋 , just checking in on this. I’ve verified that this fix allows interceptModuleExecution to handle missing modules before the pathinfo check throws, which restores the HMR recovery flow for Next.js/React Refresh.

I've also added a unit test (test/RuntimeInterception.unittest.js) that specifically checks the generated runtime string order to prevent future regressions. All CI checks are passing!

Copy link
Member

@alexander-akait alexander-akait left a comment

Choose a reason for hiding this comment

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

Please add an integration test, no need to make useless unit tests

@NihalShinde4933 NihalShinde4933 force-pushed the fix/intercept-execution-order branch from 96b3263 to 4c85b80 Compare February 21, 2026 17:31
@NihalShinde4933
Copy link
Author

Hey @alexander-akait 👋, I have updated the PR to follow the project's testing standards:

  1. Removed the unit test as requested.
  2. Added a comprehensive integration test in test/cases/runtime/intercept-module-execution.
  3. Verified formatting and passed local ConfigTestCases.

]),
"}"
]
: []),
Copy link
Member

Choose a reason for hiding this comment

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

You literally fix nothing, we should not remove this, we should FIX this

@alexander-akait
Copy link
Member

Fixed by #20510

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.

#20221 module existence check breaks interceptModuleExecution recovery for missing modules

2 participants