Skip to content

fix: web _updatePropsJS crash under strict ESM and on prop-less component refs#9870

Open
MatiPl01 wants to merge 7 commits into
mainfrom
@matipl01/web-strict-esm-updateprops-fix
Open

fix: web _updatePropsJS crash under strict ESM and on prop-less component refs#9870
MatiPl01 wants to merge 7 commits into
mainfrom
@matipl01/web-strict-esm-updateprops-fix

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Jul 3, 2026

Copy link
Copy Markdown
Member

On web, webUtils.web.ts loaded react-native-web's style helpers with require(), but the file itself is ESM. Under strict-ESM bundlers (webpack, Rollup, esbuild) and SSR there's no require, so the helpers were undefined and _updatePropsJS threw Cannot convert undefined or null to object on every frame. Metro provides require, so it was never affected.

The helpers are now imported statically from react-native-web's dist/cjs build (with .js extensions, so they resolve under Metro, strict-ESM bundlers, and Node's ESM resolver used in SSR). Static imports resolve at build time, so the helpers are always defined synchronously and styles apply from the first frame.

Also guards the props branch in _updatePropsJS so a ref without setNativeProps/style/props warns instead of throwing (hit via gifted-chat's useAnimatedKeyboard on web).

Fixes #9854

webUtils.web.ts loaded react-native-web style helpers with a bare
require() inside an ESM module, so strict-ESM bundlers (webpack, Rollup,
esbuild) and Node ESM (SSR) left the helpers undefined and _updatePropsJS
crashed on every animation frame. Keep the synchronous require() for
Metro behind a typeof-require guard and add a dynamic import() fallback
for strict ESM. Also guard the props branch so a component ref without
setNativeProps, style or props degrades to a warning instead of throwing.
@MatiPl01 MatiPl01 self-assigned this Jul 3, 2026
MatiPl01 added 2 commits July 3, 2026 17:55
- webUtils.web.ts: load the react-native-web helpers in a single top-level
  try/catch and fall back to the dist/cjs build on any require() failure, so a
  partial load is repaired; collapse the duplicated preprocess require. Kept as
  a plain try/catch (no top-level if / IIFE) so the module stays tree-shakable.
- index.ts: presence test in the _touchableNode branch so a real falsy update
  (0 / '' / false) is applied instead of silently dropped.
- Add web regression tests for _updatePropsJS (no throw on a prop-less ref,
  #9854) and web helper loading plus the dist/cjs fallback specifiers (#9844).
@MatiPl01 MatiPl01 changed the title fix: web _updatePropsJS crash under strict ESM and on prop-less component refs fix: web _updatePropsJS crash under strict ESM and on prop-less component refs Jul 3, 2026
MatiPl01 added 4 commits July 3, 2026 18:49
Import the react-native-web style helpers statically instead of a runtime
require() with an async import() fallback. Static imports resolve at build
time, so the helpers are always defined synchronously: styles apply on the
first frame, with no async gap and no case where they silently aren't applied.
The dist/cjs build with .js extensions resolves under Metro, strict-ESM
bundlers (webpack, Rollup, esbuild) and Node's ESM resolver (SSR).

createReactDOMStyle is a CJS default export so it is unwrapped; the preprocess
helpers are named exports read directly (not from `.default`), which is what
makes them resolve under both Babel and non-Babel toolchains.
@MatiPl01 MatiPl01 requested a review from tjzel July 3, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Web] _updatePropsJS throws "Cannot convert undefined or null to object" when component.props is undefined

1 participant