facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.55k stars 24.37k forks source link

[0.77][Android][JSC] Object.hasOwn is not defined, using `FlatList`, etc. #47963

Closed robhogan closed 55 minutes ago

robhogan commented 5 days ago

Description

Object.hasOwn is not implemented in the version of JSC shipped with RN Android, or on iOS < 15.4 (according to MDN-untested).

Object.hasOwn was introduced into RN core in https://github.com/facebook/react-native/pull/46386 (CC @yungsters)

We either need to replace that usage, or add a shim/polyfill for Object.hasOwn.

IMO, this is stable release blocking for RN 0.77.

Steps to reproduce

react-native$ cd packages/rn-tester
rn-tester$ yarn install-android-jsc
rn-tester$ yarn start

Navigate to FlatList -> Basic.

React Native Version

0.77.0-rc.0

Affected Platforms

Runtime - Android

Output of npx react-native info

npx react-native info
info Fetching system and libraries information...
System:
  OS: macOS 15.1.1
  CPU: (10) arm64 Apple M1 Max
  Memory: 145.30 MB / 64.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.6.0
    path: ~/.nvm/versions/node/v22.6.0/bin/node
  Yarn:
    version: 1.22.19
    path: ~/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v22.6.0/bin/npm
  Watchman:
    version: 2024-11-25T03:04:25Z
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.11.3
    path: /Users/robhogan/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK:
    API Levels:
      - "26"
      - "27"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
      - android-35 | Pre-Release 16 KB Page Size Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.15989.150.2411.11948838
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 1.8.0_302
    path: /usr/local/bin/javac
  Ruby:
    version: 2.7.6
    path: /Users/robhogan/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: Not found
  newArchEnabled: Not found
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

Warning: TypeError: Object.hasOwn is not a function. (In 'Object.hasOwn(next, key)', 'Object.hasOwn' is undefined)

This error is located at:
    in Animated(View) (created by TouchableOpacity)
    in TouchableOpacity (created by TouchableOpacity)
    in _c (created by RNTesterDocumentationURL)
    in RNTesterDocumentationURL (created by HeaderAndroid)
    in RCTView (created by View)
    in View (created by HeaderAndroid)
    in RCTView (created by View)
    in View (created by HeaderAndroid)
    in RCTView (created by View)
    in View (created by HeaderAndroid)
    in HeaderAndroid (created by RNTTitleBar)
    in RNTTitleBar (created by RNTesterApp)
    in RNTesterApp
    in RCTView (created by View)
    in View (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in RNTesterApp(RootComponent)

Reproducer

https://github.com/facebook/react-native

Screenshots and Videos

image
react-native-bot commented 5 days ago

[!WARNING] Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

NickGerleman commented 3 days ago

FYI @Kudo who has been working on updating Android JSC

0.76 requires 15.1 though, instead of 15.4, so we don’t have it supported in the current min iOS we claim to support.

Kudo commented 3 days ago

the version i updated is based on WebKitGTK 2.26.4, which is still old and would not support Object.hasOwn. there is a hard blocker for updating jsc-android to newer version. newer jsc doesn't have a way to turn off Intl support. we have to ship Intl variant only and would definitely increase apk size. that's why i plan to update jsc version and ship Intl variant only when we moving away jsc from core.

so, i would recommend a polyfill in 0.77

robhogan commented 34 minutes ago

FWIW - I originally planned to polyfill this but decided against introducing ad-hoc polyfills based on what features we (somewhat arbitrarily) might decide to use in core.

We don't currently have many (any?) polyfills for newer ES functionality, only RN-specific implementations (console, error-guard), so I'd rather continue to leave polyfills up to users/frameworks unless/until we have a consistent policy in core.

I've patched it up at the callsites to not require Object.hasOwn instead.