Skip to content

fix: refresh package type inference per compilation - #1056

Open
OskarEichler wants to merge 1 commit into
pmmmwh:mainfrom
OskarEichler:codex/react-refresh-module-cache
Open

fix: refresh package type inference per compilation#1056
OskarEichler wants to merge 1 commit into
pmmmwh:mainfrom
OskarEichler:codex/react-refresh-module-cache

Conversation

@OskarEichler

Copy link
Copy Markdown

Fix

Prevent automatic module-system inference from reusing stale package.json types across rebuilds.

The current cache is process-wide. Webpack correctly watches the discovered package.json, but after that file changes and starts a new compilation, the loader reads the old cached type instead of the updated file. Different compilation root boundaries can likewise share an inference that was valid only for the compilation that populated it.

Implementation

Keep the existing path cache per compilation in a WeakMap. Sibling modules in one compilation still avoid repeated filesystem traversal, while a new compilation re-evaluates its watched package metadata. Completed compilations and their maps can be garbage-collected.

Verification

  • Added a regression that changes a temporary package from type: module to type: commonjs between compilation contexts. It fails on current main and passes with this change.
  • Full suite including headless Chrome HMR conformance: 123 tests across 14 suites, 26 snapshots passed.
  • ESLint, Prettier, TypeScript, and whitespace checks passed.
  • React Doctor: 100/100.

Compatibility / breaking changes

No public API, dependency, runtime, or supported-platform changes. Explicit esModule options and extension-based inference remain unchanged.

@codesandbox

codesandbox Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

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