react / react/react-native

Fast Refresh not compatible with React Hooks call chain

Đang mở
#54,507 7 bình luận 8 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Debugging Issue: Author Provided Repro Needs: React Native Team Attention
Ngôn ngữ chính
C++
Star
127k
Fork
25.3k
Merge trung bình
1 ngày 23 giờ
Pull request đã merge (30 ngày)
4

Mô tả

Description

During the development process, when adding or deleting hooks, the devServer was not compatible with the destructive modifications to the hook chain. Instead, it directly caused React Native to report an error, making the application unable to run anymore and requiring a restart.

Android Platform

React has detected a change in the order of Hooks called by App. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://react.dev/link/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useSyncExternalStore       useSyncExternalStore
2. undefined                  useState
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 Error Stack:
    at App (App.tsx:18:30)
Error: Rendered more hooks than during the previous render.
    at updateWorkInProgressHook (ReactFabric-dev.js:4039:22)
    at updateReducer (ReactFabric-dev.js:4158:42)
    at useState (ReactFabric-dev.js:15273:31)
    at anonymous (react.development.js:1222:42)
    at App (App.tsx:18:30)
Steps to reproduce
  • clone this repo and run dev
  • open App.tsx
  • Comment out line 18. (code: const breakChain = useState(null);)
  • save changes
  • app was report an error
  • You can try to comment this line of code repeatedly to repeat the bug
React Native Version

0.82.1

Affected Platforms

Runtime - Android

Output of npx @react-native-community/cli info
System:
  OS: macOS 26.0.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 2.05 GB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.21.1
    path: /Users/ollie/.nvm/versions/node/v22.21.1/bin/node
  Yarn:
    version: 1.22.22
    path: /Users/ollie/.nvm/versions/node/v22.21.1/bin/yarn
  npm:
    version: 10.9.4
    path: /Users/ollie/.nvm/versions/node/v22.21.1/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.27812.49.2514.14217341
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.17
    path: /Users/ollie/.jenv/shims/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.1
    wanted: 19.1.1
  react-native:
    installed: 0.82.1
    wanted: 0.82.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false
Stacktrace or Logs
React has detected a change in the order of Hooks called by App. This will lead to bugs and errors if not fixed. For more information, read the Rules of Hooks: https://react.dev/link/rules-of-hooks

   Previous render            Next render
   ------------------------------------------------------
1. useSyncExternalStore       useSyncExternalStore
2. undefined                  useState
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 Error Stack:
    at App (App.tsx:18:30)
MANDATORY Reproducer

https://github.com/NiuGuohui/ReactNativeFastRefreshBug

Screenshots and Videos

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với reproducer bắt buộc và dòng 18 của App.tsx, sau đó tái hiện vấn đề trên Android với React Native 0.82.1 trong khi liên tục comment và bỏ comment hook. Điều tra hành vi của Fast Refresh và devServer xung quanh chuỗi hook đã thay đổi. Hoàn tất khi việc lưu các chỉnh sửa này không còn khiến ứng dụng không thể chạy hoặc yêu cầu khởi động lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
react-native, typescript
Lĩnh vực
developer-experience, mobile
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.