Skip to content

fix: capture window dimensions in layout worklet - #2751

Open
huytdps13400 wants to merge 1 commit into
gorhom:masterfrom
huytdps13400:fix/2734-capture-window-dimensions
Open

fix: capture window dimensions in layout worklet#2751
huytdps13400 wants to merge 1 commit into
gorhom:masterfrom
huytdps13400:fix/2734-capture-window-dimensions

Conversation

@huytdps13400

Copy link
Copy Markdown

Motivation

Since v5.2.14, the Dimensions listener in useAnimatedLayout destructures its payload into a local named window. Reanimated treats window as an ambient default global, so it does not capture that binding in the state.modify worklet closure. Native UI runtimes have no global window, and every dimensions change can therefore throw ReferenceError: Property 'window' doesn't exist.

This renames the binding to windowDimensions, which Reanimated captures, and removes the Dimensions subscription when the hook unmounts so repeated sheet mounts do not accumulate listeners.

Closes #2734

Verification

  • RED Babel/Reanimated 3.19.1 transform of the previous callback produced __closure = {} while its worklet body referenced window.
  • GREEN transform of the committed file produces __closure = { windowDimensions: windowDimensions } and includes subscription.remove() cleanup.
  • yarn typescript
  • yarn build
  • yarn biome check --error-on-warnings src/hooks/useAnimatedLayout.ts
  • Full yarn lint reaches one pre-existing warning in src/hooks/useBoundingClientRect.ts:54; the changed file is clean.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ReferenceError: Property 'window' doesn't exist in useAnimatedLayout worklet on any Dimensions change (regression in 5.2.14)

1 participant