fix: remove deep imports from 'react-native' - #18
Merged
Conversation
React Native 0.80 deprecated deep imports from `react-native/Libraries/*`, and 0.87 enables the Strict TypeScript API by default, which blocks them at the type level. `./Libraries/*` still resolves at runtime, but it is now explicitly outside the public API contract. Replace both internal modules with local implementations built on the public API: - `dev-server.ts` derives the Metro origin from `NativeModules.SourceCode.getConstants().scriptURL`, matching upstream's cache and localhost fallback semantics. `NativeModules` is a public root export of the Strict API. - `symbolicate.ts` posts directly to Metro's `symbolicate` endpoint, which is all the upstream module did. The alternative, `react-native/unstable-internals-do-not-use`, exports `getDevServer` but not `symbolicateStackTrace`, requires consumers to set a `customConditions` entry in their tsconfig, and does not exist before 0.87. Also drops the now-unneeded ambient `declare module` shim. Closes #17 Claude-Session: https://claude.ai/code/session_01KDiabfZtYE2vxCeybZnA4D
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.
Closes #17.
React Native 0.80 deprecated deep imports from
react-native/Libraries/*, and 0.87 enables the Strict TypeScript API by default, which blocks them at the type level. We imported two internal modules, which produced deprecation warnings in every consumer app:Checked against the published
react-native@0.87.1tarball:./Libraries/*still resolves at runtime ("default": "./Libraries/*.js") but itstypesentry is nownull, and thereact-native-legacy-deep-importsopt-out is scheduled for removal in 0.88. SoLibraries/is now explicitly outside the API contract — Meta can relocate these files in any release without it counting as breaking.What changed
Both modules are reimplemented locally on top of React Native's public API:
src/react-native/dev-server.ts— derives the Metro origin fromNativeModules.SourceCode.getConstants().scriptURL, with the same caching andhttp://localhost:8081/fallback semantics as upstream.NativeModulesis a public root export of the Strict API (types_generated/index.d.ts:123). Falls back tosourceCode.scriptURLfor older React Native versions that expose it as a plain constant, and tolerates the module throwing or being absent.src/react-native/symbolicate.ts— posts directly to Metro'ssymbolicateendpoint with{stack, extraData}. That is all the upstream module did, and we already hand-roll its siblings (open-stack-frameinopen.ts,/__react-native-grab/copyincopy.ts).open.ts,copy.ts, andget-rendered-by.tsnow point at these. The ambientdeclare module "react-native/Libraries/Core/Devtools/getDevServer"shim inget-dev-server.d.tsis deleted — nothing needs it anymore.Why not
unstable-internals-do-not-use0.87 added
react-native/unstable-internals-do-not-useas a sanctioned compatibility bridge for libraries in exactly this position. It was the obvious candidate, but it does not fit:getDevServerbut notsymbolicateStackTrace, so it only solves half the problem;"customConditions": ["react-native-unstable-internals"]to their tsconfig for types to resolve — a bad ask for a library;There is also no
globalThisescape hatch — the only relevant global in 0.87.1 isglobal.__METRO_GLOBAL_PREFIX__ + '__loadBundleAsync', which does not expose the dev server URL.Result
Zero deep imports, zero warnings, no consumer tsconfig requirement, and support across all React Native versions including pre-0.87. Verified on the built output:
Testing
8 new unit tests covering scriptURL parsing, the localhost fallback for release bundles, the legacy plain-constant path, a throwing native module, caching, the symbolicate request shape, the not-loaded-from-Metro guard, and error statuses.
npm test26 passed ·npm run lintclean ·npm run buildclean.https://claude.ai/code/session_01KDiabfZtYE2vxCeybZnA4D