Move AssetRegistry implementation into main package#57233
Open
huntie wants to merge 2 commits into
Open
Conversation
Summary: Quality pass on the `assets-registry` package ahead of the next diff. - Add user-facing notes to package README. - Add adjacent `.d.ts` definitions (manually/AI-maintained is fine at this scale). - Move source files to `src/` (`"exports"` map added; no breaking changes). Changelog: [Internal] Differential Revision: D108624321
Summary: **Problem** The separate `react-native/assets-registry` package isn’t working for the ecosystem. `registry.js` holds asset state in a module-scoped variable, which makes the package a stateful singleton: exactly one instance must exist per JS runtime, or registration and lookup diverge. We provide no guarantee that this singleton requirement holds: - The install layout — how the package manager dedupes packages in `node_modules` — decides how many copies exist, and `react-native`'s exact-version pin means third-party ranges never dedupe against it. Effects: - **Consumers silently break**: `expo-asset` and `expo-image` can land on a second copy: assets register in one, resolve as `undefined` from the other. Expo neutralizes this with a shim in `expo/cli` that redirects every registry import to a single virtual module — bare React Native + Metro has no such protection. - **This blocks 1.0**: The ecosystem can't move from exact-version lockstep to semver ranges until stateful packages like the asset registry are safe to duplicate. Today, relaxing the pin would turn a latent footgun into a common one. **To solve this**, move towards (but not quite yet) deleting `react-native/assets-registry`, in favour of a replacement `AssetRegistry` API offered directly by `react-native`. **This diff** - Adds new `AssetRegistry` API, along with the `PackagerAsset` and `AssetDestPathResolver` root type exports in `react-native`. - Updates `react-native/assets-registry` to source from this relocated implementation — fixing the duplicate install layout bug (where apps/frameworks enforce a single copy of `react-native`). **Impact** - **✅ Fixed**: Imports from either `react-native` or `react-native/assets-registry` in RN 0.87+ will be durable to duplicate package installs — Expo can remove their virtual module shim. Changelog: - [General][Fixed] - **assets-registry**: `react-native/assets-registry` now shares state across duplicate installs, sourcing from a relocated implementation in the `react-native` package - [General][Added] - Add `AssetRegistry` API (replaces `react-native/assets-registry/registry`) Differential Revision: D108750302
|
@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D108750302. |
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
Member
Author
|
cc @byCedric |
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.
Summary:
Problem
The separate
@react-native/assets-registrypackage includes a longstanding ecosystem footgun.registry.jsholds asset state in a module-scoped variable, which makes the package a stateful singleton: exactly one instance must exist per JS runtime, or registration and lookup diverge.We provide no guarantee that this singleton requirement holds:
node_modules— decides how many copies exist, andreact-native's exact-version pin means third-party ranges never dedupe against it.Effects:
expo-assetandexpo-imagecan land on a second copy: assets register in one, resolve asundefinedfrom the other. Expo neutralizes this with a shim inexpo/clithat redirects every registry import to a single virtual module — bare React Native + Metro has no such protection.To solve this, move towards (but not quite yet) deleting
@react-native/assets-registry, in favour of a replacementAssetRegistryAPI offered directly byreact-native.This diff
AssetRegistryAPI, along with thePackagerAssetandAssetDestPathResolverroot type exports inreact-native.@react-native/assets-registryto source from this relocated implementation — fixing the duplicate install layout bug (where apps/frameworks enforce a single copy ofreact-native).Impact
react-nativeor@react-native/assets-registryin RN 0.87+ will be durable to duplicate package installs — Expo can remove their virtual module shim.Changelog:
@react-native/assets-registrynow shares state across duplicate installs, sourcing from a relocated implementation in thereact-nativepackageAssetRegistryAPI (replaces@react-native/assets-registry/registry)Differential Revision: D108750302