fix: declare react and react-native as peer dependencies#817
Open
patrickwehbe wants to merge 1 commit into
Open
fix: declare react and react-native as peer dependencies#817patrickwehbe wants to merge 1 commit into
patrickwehbe wants to merge 1 commit into
Conversation
The package only listed react and react-native under devDependencies and had no peerDependencies field. In pnpm monorepos with strict (default) node-linker, a package only resolves the dependencies it declares, so the slider would not link the host app's react/react-native. That results in a second copy of React being loaded and the classic 'Invalid hook call. Hooks can only be called inside of the body of a function component' runtime error. Declaring react and react-native as peers lets the package manager deduplicate them against the host app's installed versions. Wide '*' ranges follow the convention used by other callstack React Native libraries such as react-native-paper, since the slider supports a broad range of React Native versions. The pinned dev versions are kept for the example app and tests. Fixes callstack#769
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
The published package declares
reactandreact-nativeonly underdevDependenciesand has nopeerDependenciesfield, so package managers have no way to know the slider expects them to be provided by the host app.This breaks in pnpm monorepos. With pnpm's default (strict) node-linker, a package can only resolve the dependencies it explicitly declares. Because the slider does not declare
react/react-nativeas deps or peers, pnpm does not link the host app's copies to it. The result is a second copy of React getting loaded, which throws the classic:Declaring
reactandreact-nativeas peer dependencies lets the package manager deduplicate them against whatever the host app already has installed. I used wide*ranges to match the convention already used by other callstack React Native libraries (for example react-native-paper), since the slider works across a broad range of React Native versions and should not artificially constrain consumers. The pinned dev versions are kept as-is for the example app and tests.Fixes #769
Test Plan
node -e "JSON.parse(require('fs').readFileSync('package/package.json'))"parses with no error.peerDependenciesblock resolves to{"react":"*","react-native":"*"}and thatdevDependenciesstill pinsreact ^19.2.0/react-native ^0.81.4.peerDependenciesfield; no source or build behavior changes.