Deprecate @react-native/assets-registry#57370
Open
huntie wants to merge 3 commits into
Open
Conversation
Summary: **Context** This stack intends to relocate `AssetRegistry` API from `react-native/assets-registry` into `react-native` — addressing runtime safety and public deep imports issues (1.0 and JS Stable API blockers). **This diff** Create a new `react-native/asset-utils` package, intended for internal/framework use (read: **will not be an end user concern**). This re-houses `react-native/assets-registry/path-support.js`. Stacked with the next two diffs, this contributes to the 0.87 objective to delete `react-native/assets-registry` towards install-layout-safe behaviour and JS deep import removal. - (Temporarily, this leaves two copies of `path-support.js` until I enact the package removal down the stack.) This change also enables us to de-duplicate `assetPathUtils.js` inside `community-cli-plugin` and use one source of truth. - Additionally, we have fbsource consumers of this util that cannot have a circular Buck dep on `react-native`, so the main package was not a suitable relocation point (secondarily to not adding an awkward new public API here). **Changes** - Add `react-native/asset-utils` (`packages/asset-utils/`): `src/AssetPathUtils.js` containing Android path helpers and tests. - De-duplicate usages in `community-cli-plugin`: delete `src/commands/bundle/assetPathUtils.js`. Changelog: [General][Added] - Introduce `react-native/asset-utils` package (relocates Android path utils for libraries/frameworks) Differential Revision: D110045272
… API Summary: NOTE: Squash of react#57233 (D108750302) and react#57232 (D108750303) **This diff** solves two distinct problems. **Problem 1 — `react-native/assets-registry` is a stateful-singleton footgun.** `registry.js` holds asset state in a module-scoped variable, so exactly one instance must exist per JS runtime or registration and lookup diverge. Nothing guarantees this: the `node_modules` install layout decides how many copies exist, and `react-native`'s exact-version pin means third-party ranges never dedupe against it. Consumers silently break — `expo-asset`/`expo-image` can land on a second copy where assets register in one and resolve as `undefined` from the other (Expo neutralizes this with a virtual-module shim in `expo/cli`; bare React Native + Metro has no such protection). It also blocks 1.0: the ecosystem can't move from exact-version lockstep to semver ranges until stateful packages like this are safe to duplicate. **Problem 2 — Metro configs depend on a deep `/Libraries/...` import.** Metro configs reference `transformer.assetRegistryPath` via a deep `react-native/Libraries/Image/AssetRegistry` import. We want to replace it with a public entry point, but we can't reuse the new index `AssetRegistry` API directly — doing so breaks Metro's API contract (it generates an inline require). We need a dedicated wrapper module that can be read without destructuring. **This diff** 1. Moves the `AssetRegistry` implementation into the main `react-native` package, adding the `AssetRegistry` API plus the `PackagerAsset` and `AssetDestPathResolver` root type exports. `react-native/assets-registry` now sources from this relocated implementation, fixing the duplicate-install bug wherever apps/frameworks enforce a single copy of `react-native`. Imports from either package in RN 0.87+ become durable to duplicate installs, so Expo can drop their virtual-module shim. 2. Adds a new `react-native/asset-registry` secondary entry point, intended and documented for the Metro config use case, and migrates our own `react-native/metro-config` onto it (replacing the `transformer.assetRegistryPath` deep import). Deprecates `react-native/assets-registry/registry` and removes `react-native/Libraries/Image/AssetRegistry`, standardizing on `AssetRegistry` (singular) as canonical. 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`) - [General][Breaking] - `react-native/Libraries/Image/AssetRegistry` is removed. Please use the `AssetRegistry` API (apps/library code) and/or the `react-native/asset-registry` entrypoint (Metro/build configs). - [General][Deprecated] - **assets-registry**: `react-native/assets-registry/registry` is deprecated. Please use the `AssetRegistry` API (apps/library code) and/or the `react-native/asset-registry` entrypoint (Metro/build configs). Differential Revision: D109019622
Summary: **Context** This stack intends to relocate `AssetRegistry` API from `react-native/assets-registry` into `react-native` — addressing runtime safety and public deep imports issues (1.0 and JS Stable API blockers). **This diff** Deprecate the `react-native/assets-registry` package, replaced by changes in the last two diffs: - `react-native/assets-registry/registry` → use `AssetRegistry` from `react-native` (or the `react-native/asset-registry` build entry point). - `react-native/assets-registry/path-support` → use `react-native/asset-utils`. **Deprecation plan** The package will be deprecated for **two release cycles** (0.87 + 0.88) and deleted in 0.89. Changelog: [General][Deprecated] - Deprecate `react-native/assets-registry`. Use `AssetRegistry` from `react-native` and `react-native/asset-utils` instead. Differential Revision: D110053924
|
Warning JavaScript API change detected This PR commits an update to
This change was flagged as: |
|
@huntie has exported this pull request. If you are a Meta employee, you can view the originating Diff in D110053924. |
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:
Context
This stack intends to relocate
AssetRegistryAPI from@react-native/assets-registryintoreact-native— addressing runtime safety and public deep imports issues (1.0 and JS Stable API blockers).This diff
Deprecate the
@react-native/assets-registrypackage, replaced by changes in the last two diffs:@react-native/assets-registry/registry→ useAssetRegistryfromreact-native(or thereact-native/asset-registrybuild entry point).@react-native/assets-registry/path-support→ usereact-native/asset-utils.Deprecation plan
The package will be deprecated for two release cycles (0.87 + 0.88) and deleted in 0.89.
Changelog:
[General][Deprecated] - Deprecate
@react-native/assets-registry. UseAssetRegistryfromreact-nativeand@react-native/asset-utilsinstead.Differential Revision: D110053924