callstack / callstack/react-native-slider

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

Abierto Apto para principiantes
#769 0 comentarios 0 reacciones 0 asignados Ver en GitHub
bug report
Lenguaje dominante
TypeScript
Estrellas
1.4k
Forks
295
Merge medio
5 min
PR fusionados (30 d)
1

Descripción

## Environment

* react-native info output:
```
react-native: 0.81.5
react: 19.1.0
expo: 54.0.33
@react-native-community/slider: 5.1.2
```

* are you using the new architecture?
Yes

* which version of react & react-native are you using?
React 19.1.0, React Native 0.81.5

## Description

@react-native-community/slider does not declare react or react-native in its peerDependencies. This causes duplicate React instances in pnpm monorepos with strict dependency isolation, resulting in the classic "Invalid hook call" runtime error.

Root cause
The slider package uses React internally (hooks, JSX) but its package.json has no peerDependencies field. In pnpm monorepos without nodeLinker: hoisted, each package only sees its own declared dependencies. Since pnpm doesn't know the slider needs React, it doesn't link the host app's React to the slider. At runtime, the slider resolves a different React copy from pnpm's internal store, causing two React instances in the same app.

Error

ERROR Invalid hook call. Hooks can only be called inside of the body of a function component.
This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
Workaround
Adding packageExtensions in the root package.json fixes it:

```
{
"pnpm": {
"packageExtensions": {
"@react-native-community/slider": {
"peerDependencies": {
"react": "*",
"react-native": "*"
}
}
}
}
}
````

Suggested fix
Add peerDependencies to the slider's package.json:

```
"peerDependencies": {
"react": "*",
"react-native": "*"
}
```

This is consistent with how other React Native libraries declare their peer dependencies (e.g. react-native-reanimated, react-native-gesture-handler, @gorhom/bottom-sheet).

## Reproducible Demo

Create a pnpm monorepo with two apps (e.g. a Next.js web app using React 19.2.x and a React Native app using React 19.1.0)
Do not use nodeLinker: hoisted in pnpm-workspace.yaml (pnpm's default strict isolation)
Install @react-native-community/slider in the React Native app
Use the component
The app crashes at runtime with "Invalid hook call" because the slider resolves a different React instance from pnpm's .pnpm/node_modules/react

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con el package.json del paquete slider e inspecciona cómo están declaradas sus dependencias. Añade las declaraciones de peer dependencies solicitadas y, a continuación, verifica que la reproducción del monorepo de pnpm ya no resuelva una instancia separada de React y evite el invalid hook call.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
react, react-native
Área
mobile
Tipo de issue
Error
Dificultad
1/5
Tiempo estimado
Menos de una hora
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
68/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.