fix: preserve default-scope shared cache aliases#862
Merged
gioboa merged 5 commits intoJun 26, 2026
Conversation
commit: |
Collaborator
|
@abhayzmp is this pre-release working for you? |
|
I work in IST hours and I'm packed up for the day. But feel free to just clone the repro and follow readme.md to test the changes. Once I login tomorrow I can test and revert |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Close #858
Follow-up to #861
Summary
This adds a shared cache compatibility layer for default share-scope modules.
#861 fixes the dev
optimizeDepsgate for shared singleton React, but the repro in #858 can still fail when generated runtime code looks for the same shared module under different cache keys. Newer scoped cache keys use values such asdefault:react, while default-scope compatibility paths can still observe the older unscoped shape, such asreact.This patch centralizes that behavior with a canonical shared cache descriptor plus default-scope aliases.
Problem
Shared dependency configuration and runtime shared cache storage are separate layers.
For example:
At runtime, generated
loadSharewrappers andremoteEntrycode store resolved shared modules inglobalThis.__mf_module_cache__.share.The same default-scope shared module may be addressed as:
If one generated path writes
default:reactwhile another path readsreact, the remote can miss the host-provided singleton and fall back to its own React instance. That can still produce duplicate React symptoms even after React is excluded from dev pre-bundling.Changes
Added
getSharedCacheDescriptor()insrc/utils/packageUtils.ts.canonicalis the scoped cache key, for exampledefault:react.aliasescontains default-scope compatibility keys, for examplereact.Added generated runtime helpers:
__mfGetSharedCacheDescriptor__mfReadSharedCache__mfWriteSharedCacheUpdated generated
loadSharemodules to read and write through the shared cache helpers.Updated generated
remoteEntryand host auto-init code to use the same helpers for:import: falseshared provider seeding,Updated the
react/compiler-runtimepre-build path to resolve React through the same compatible shared cache read.Tests
Added
src/utils/__tests__/packageUtils.test.tscoverage for:Updated virtual module tests to assert shared cache helper usage in generated
loadShare,remoteEntry, and host auto-init code.Updated integration coverage to verify generated shared chunks use the compatibility helpers and default-scope descriptors.
Verification
Results:
pnpm exec vitest run --dir srcstill prints the existingMaxListenersExceededWarning, but all tests pass.Compatibility Notes
This intentionally keeps default-scope compatibility while preserving custom-scope isolation.
New generated code reads the canonical key first. If only a default-scope alias exists, the helper promotes that value to the canonical key. Writes always store the canonical key and also fill empty alias slots for default-scope compatibility.
This should allow version-skewed host and remote builds to share the same singleton module while avoiding cross-scope collisions.