fix: replace deep RN imports with public API - #744
Conversation
leotm
left a comment
There was a problem hiding this comment.
didn't commit the import updates 🤦♂️
- replace imports from RN internal paths (react-native/Libraries/Types/CodegenTypes, react-native/Libraries/Utilities/codegenNativeComponent) with public API exports - fix implicit any type in SafeAreaContext cb param and avoid InstanceType on codegen component by using Component<Props> directly
43b2f7d to
9879709
Compare
9879709 to
6612ea2
Compare
There was a problem hiding this comment.
Thanks @leotm!
✅ Endorsed
However, this is a breaking change as it'll require RN >= 0.82, which introduces CodegenTypes. cc @janicduplessis
(Note: not 0.80, it needs slightly revised types from >= 0.82.)
"peerDependencies": {
"react": "*",
- "react-native": "*"
+ "react-native": ">=0.82.0"
},Non-breaking fix: #745
Fundamentally this issue should only be happening when this repository upgrades react-native for its typechecking, however the root issue is that the jest/mock subpath breaks encapsulation. I've opened this separate PR which can be landed as a non-breaking change fix for the user side.
(In contrast, this PR fixes the library's own codebase.)
- replace imports from RN internal paths with public API exports - react-native/Libraries/Types/CodegenTypes - react-native/Libraries/Utilities/codegenNativeComponent - react-native/Libraries/TurboModule/TurboModuleRegistry - update peerDep react-native from * to >=0.82.0 - document RN bug (TODO: file/fix upstream)
6612ea2 to
2f3adcb
Compare
| // NB: we can't name this to "Double" due to a @react-native/codegen bug | ||
| // otherwise ESLint will finish parsing, but the Node process infinitely hangs | ||
| // @react-native/eslint-plugin-specs provides rule @react-native/specs/react-native-modules to parse TurboModule specs with @react-native/codegen | ||
| // which sadly enters a type resolution loop when the alias name matches the RHS | ||
| // (i.e. type Double = CodegenTypes.Double → resolves to "Double" → finds same alias → loop) | ||
| // Ref: https://github.com/react/react-native/blob/85e07db3e8295ccf59779fc82a4f953e54ebeb45/packages/react-native-codegen/src/parsers/typescript/parser.js#L459-L478 | ||
| type _Double = CodegenTypes.Double; |
There was a problem hiding this comment.
i'll open an issue upstream later then fix cc @huntie wdyt
Context
Fix: leotm/react-native-template-new-architecture#2041
Fix: #743