Skip to content

When the ReactNative rendering function encounters an error, it will trigger the rendering function again and swallow some error information. #54331

@mackwang112

Description

@mackwang112

Description

reproduction demo

let count = 0;

const App = () => {
  console.log('render App...................' + ++count)
  throw new Error("Test Error: count=" + count);
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Text>React Native Project 77</Text>
    </View>
  )
};

Under [email protected], the error message printed in the console is Test Error: count=3.

Expected result: Error messages should include Test Error: count=1

Image

It can be found that the render App.................... prints multiple times, and this phenomenon only occurs when there is an error in the render function. If there is no error in the render function, the render App prints only once, and the count is 1.
Image

This will make it difficult for developers to troubleshoot errors, as there are inevitably some side effects or caches in the code. The same code does not always result in the same error when run twice, and the error information from the first render is the actual error, while what developers see is not it.

It is worth noting that in [email protected], although it will also trigger two renders, the printed error information count is 1, which is beneficial for developers to locate the actual error.

Image

This is a v0.72.17 reproduction demo.

And in 0.77.2, print Test Error: count=2, it also does not meet expectations.

This is a v0.77.2 reproduction demo.

In addition, I would like to know why a re-render is triggered when an error occurs. Are there any articles or discussions that can help me better understand this point?

Steps to reproduce

1: npm install
2: cd ios && pod install && cd ../
3: npm run start
4: npm run ios

React Native Version

0.82.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

System:
  OS: macOS 26.0.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 217.98 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 23.9.0
    path: /Users/didi/.nvm/versions/node/v23.9.0/bin/node
  Yarn: Not Found
  npm:
    version: 10.9.2
    path: /Users/didi/.nvm/versions/node/v23.9.0/bin/npm
  Watchman:
    version: 2025.06.23.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/didi/.rbenv/shims/pod
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.12
    path: /Users/didi/.jenv/shims/javac
  Ruby:
    version: 3.2.8
    path: /Users/didi/.rbenv/shims/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: true
  newArchEnabled: true

Stacktrace or Logs

n

MANDATORY Reproducer

https://github.com/mackwang112/reproducer-react-native

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions