v3 `usePanGesture`: `validateOffsetsArray` reads shared values during render (Reanimated warning in `__DEV__`)

オープン 初心者向け
#4,725 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
react, react-native, typescript
領域
frontend, mobile

調査の方向性

src/v3/hooks/gestures/pan/usePanGesture.tsから始め、特にvalidateOffsetsArrayとvalidatePanConfigからの呼び出しを確認します。Shared Valuesの型付けと、既存のリスナーによる受け渡しを追跡します。issueの再現手順で開発時の警告を確認してから、activeOffsetXのShared Valuesを対象にしたテストを追加または更新します。通常の数値オフセットも引き続き正しく検証されることを確認します。

索引モデルが issue の本文から書いたものです。

説明

Missing info Missing repro Platform: iOS

In __DEV__, usePanGesture calls validatePanConfig synchronously while rendering. validateOffsetsArray unpacks the array entries with maybeUnpackValue, which reads .value of a shared value. Reanimated then warns on every render:

[Reanimated] Reading from `value` during component render. Please ensure that you do not access the `value` property or use `get` method of a shared value while React is rendering a component.

Environment: react-native-gesture-handler 3.3.0 (code unchanged in 3.5.1), react-native-reanimated 4.7.1, Expo SDK 58, React Native 0.88.1, iOS 27.

Steps to reproduce:

const reach = useSharedValue(-40);
const pan = usePanGesture({ activeOffsetX: [reach, 20], onUpdate: () => {} });

Render the component in a dev build: the warning appears on every render (the types allow shared values inside these arrays via WithSharedValue).

Root cause: src/v3/hooks/gestures/pan/usePanGesture.ts:46-47 (maybeUnpackValue<number>(offsets[0]), called from validatePanConfig at line 57-60 and from the hook body at line 152).

Fix: validate only plain numbers; shared values are forwarded to the native side by the existing listeners anyway, so they are not validated at render time:

-  const offsetStart = maybeUnpackValue<number>(offsets[0]);
-  const offsetEnd = maybeUnpackValue<number>(offsets[1]);
-
-  if (offsetStart > 0 || offsetEnd < 0) {
+  const [offsetStart, offsetEnd] = offsets;
+
+  if (
+    (typeof offsetStart === 'number' && offsetStart > 0) ||
+    (typeof offsetEnd === 'number' && offsetEnd < 0)
+  ) {

The maybeUnpackValue import (line 11) then becomes unused. Happy to send this as a PR.

主要言語
TypeScript
スター
6.8k
フォーク
1.1k
平均マージ
4日 4時間
マージ済み PR(30日)
22

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-gesture-handler のほかの issue

software-mansion/react-native-gesture-handler の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。