[metro-cache] metro-cache preview#4576
Draft
zhongwuzw wants to merge 12 commits intomodule-federation:mainfrom
Draft
[metro-cache] metro-cache preview#4576zhongwuzw wants to merge 12 commits intomodule-federation:mainfrom
zhongwuzw wants to merge 12 commits intomodule-federation:mainfrom
Conversation
❌ Deploy Preview for module-federation-docs failed. Why did it fail? →
|
|
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.
Description
Introduces
@module-federation/metro-cache, a new React Native native module that provides persistent on-disk caching for federated remote bundles. This eliminates redundant network downloads on app cold starts by caching bundles locally and validating them against manifest hashes (SHA-256).What's new
@module-federation/metro-cache(new package)NativeMFECacheAPI:downloadFile,evaluateJavaScript,deleteFile,getFileSize,getDocumentDirectoryCacheManager: disk-backed cache index with LRU eviction, host build hash invalidation, and disk manifest persistencemaxCacheSizeBytes,maxAgeMs,minCacheSizeBytesreact-native.config.js@module-federation/metro(metro-core) changesasyncRequire.ts: intercepts bundle loads with a cache layer — checks manifest hash → cache hit (eval from file) / cache miss (download + verify SHA-256 + persist) / fallback to network on mismatchcache-interface.ts:ICacheManager/ICacheNativeinterfaces for loose coupling between metro-core and metro-cache (graceful degradation when metro-cache is not installed)metroCorePlugin.ts:afterResolvehook extracts bundle hashes from manifest (metaData.buildInfo.hash,exposes[].hash,shared[].hash) into a global__MFE_BUNDLE_HASHES__map consumed by the cache layerbundle-remote/index.ts: hash computation during production bundle buildsCache flow
bundle request → check MFE_BUNDLE_HASHES for expected hash
├─ no hash → fallback to loadBundleAsync (no cache)
└─ has hash → check CacheManager
├─ cache HIT + hash match → eval from local file
└─ cache MISS or hash mismatch → downloadFile → verify SHA-256
├─ match → persist to cache + eval from file
└─ mismatch → delete file + fallback to loadBundleAsync
Related Issue
Types of changes
Checklist