Skip to content

fix: declare react and react-native as peer dependencies#817

Open
patrickwehbe wants to merge 1 commit into
callstack:mainfrom
patrickwehbe:fix/769-peer-dependencies
Open

fix: declare react and react-native as peer dependencies#817
patrickwehbe wants to merge 1 commit into
callstack:mainfrom
patrickwehbe:fix/769-peer-dependencies

Conversation

@patrickwehbe

Copy link
Copy Markdown

Summary

The published package declares react and react-native only under devDependencies and has no peerDependencies field, 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-native as 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:

Invalid hook call. Hooks can only be called inside of the body of a function component.

Declaring react and react-native as 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.
  • Confirmed the new peerDependencies block resolves to {"react":"*","react-native":"*"} and that devDependencies still pins react ^19.2.0 / react-native ^0.81.4.
  • The change is limited to adding the peerDependencies field; no source or build behavior changes.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Missing peerDependencies for react and react-native causes duplicate React instances in pnpm monorepos

1 participant