meliorence / react-native-render-html

iOS/Android pure javascript react-native component that renders your HTML into 100% native views
https://meliorence.github.io/react-native-render-html/
BSD 2-Clause "Simplified" License
3.48k stars 588 forks source link

Lots of warnings logged in tests with fake timers #665

Open TuurDutoit opened 3 months ago

TuurDutoit commented 3 months ago

Decision Table

Good Faith Declaration

Description

When using jest.useFakeTimers() in tests, RNRH logs a whole lot of warnings, even when only rendering the component once.

I've also found the root cause. When using the fake timers, Jest patches performance.now() (among others). Crucially, it sets the return value to 0 by default (you can advance this value using jest.advanceTimersByTime() and related utilities, but the default is 0) Unfortunately, RNRH also uses 0 as the default of the lastUpdate ref (source). Therefore, on the very first render, RNRH thinks the previous render happened exactly 0ms ago, and prints a bunch of warnings!

I realize this is not really a "bug" per se, and definitely won't affect any end users. However, it might confuse other devs like it confused me, and the fix is probably quite simple.

React Native Information

System:
  OS: macOS 14.2.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 1.43 GB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.13.1
    path: /private/var/folders/fk/c9z1tyhj02nfdn9dz_71vjk80000gq/T/xfs-3bfe75a4/node
  Yarn:
    version: 3.2.3
    path: /private/var/folders/fk/c9z1tyhj02nfdn9dz_71vjk80000gq/T/xfs-3bfe75a4/yarn
  npm:
    version: 10.5.2
    path: ~/.local/state/fnm_multishells/1402_1720596864919/bin/npm
  Watchman:
    version: 2024.05.06.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.0
    path: /Users/tuur/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.2 AI-222.4459.24.2221.9862592
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /Users/tuur/.jenv/shims/javac
  Ruby:
    version: 3.0.6
    path: /Users/tuur/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.14
    wanted: 0.72.14
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

RNRH Version

6.3.4

Tested Platforms

Reproduction Platforms

Minimal, Reproducible Example

https://github.com/meliorence/react-native-render-html/pull/664

Additional Notes

No response

jsamr commented 3 months ago

@TuurDutoit Appreciate the excellent submission and reproduction, thank you!