fix: support CSS asset resolution on React Native 0.87 - #3019
Open
giaBaoJS wants to merge 1 commit into
Open
Conversation
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
Fixes #3015.
React Native 0.87 no longer installs
@react-native/assets-registrytransitively, so importingreact-native-svg/cssfailed while Metro resolvedLocalSvgandresolveAssetUri.This change resolves native numeric assets through the public
Image.resolveAssetSourceAPI instead. That API is available across react-native-svg's supported React Native range and delegates to the registry owned by the installed React Native version.The existing registry-based implementation is retained in
resolveAssetUri.web.ts. React Native Web does not exposeImage.resolveAssetSource, so using a platform file avoids changing its asset behavior.I did not use either suggested React Native 0.87-only entry point:
react-native/asset-registryis first exported in React Native 0.87;AssetRegistrynamed export is also absent in React Native 0.78–0.86.Adding a standalone registry dependency would also risk resolving a different registry version/instance from the one used by React Native. The public Image resolver keeps the library compatible with React Native 0.78 through 0.87 without adding a dependency.
Test Plan
React Native 0.87 package-consumption reproduction
I packed the actual package, installed it into the repository's React Native 0.87 test app, removed access to parent
node_modules, and bundled an entry importingreact-native-svg/css.Before the change:
The app had no direct
node_modules/@react-native/assets-registryinstallation. With a tarball built from this branch, the same command succeeds:Oldest supported representative
The same fixed tarball bundles successfully in an isolated React Native 0.78.3 consumer:
Regression tests
Keeping the final tests while reverting only the native source change produces:
Restoring the change gives 6/6 passing. I also inserted a deliberate failing sentinel into the new suite and confirmed Jest reported that exact assertion, proving the harness collects the file.
Final checks:
Compatibility
Checklist
README.md(not applicable)__tests__folder