Skip to content

fix: add typeof guard for getBoundingClientRect in useBoundingClientRect#2626

Open
magrinj wants to merge 1 commit intogorhom:masterfrom
magrinj:patch-1
Open

fix: add typeof guard for getBoundingClientRect in useBoundingClientRect#2626
magrinj wants to merge 1 commit intogorhom:masterfrom
magrinj:patch-1

Conversation

@magrinj
Copy link
Copy Markdown
Contributor

@magrinj magrinj commented Mar 2, 2026

PR #2561 fixed the unstable_getBoundingClientRect path (line 58) by adding a typeof === 'function' guard, but the fallback getBoundingClientRect path (line 71) was missed, it still only checks !== null.

In react-test-renderer, nativeFabricUIManager is set to {} by React Native's jest setup (react-native/jest/setup.js line 36), which makes isFabricInstalled() return true. This causes the useBoundingClientRect hook to execute the Fabric code path. Since getBoundingClientRect is undefined (not null) on test renderer refs, the !== null check passes and the call crashes:

TypeError: ref.current.getBoundingClientRect is not a function at useBoundingClientRect.ts:73:34

This affects any jest test that renders a BottomSheet component deeply enough to trigger the hook.

Fixes #2625
Reproduction: https://github.com/magrinj/bottom-sheet-test-bug

@SellersEvan
Copy link
Copy Markdown

I am experiencing this issue as well. I believe it started happening on Expo SDK 55.

@chukwumaokere
Copy link
Copy Markdown

@SellersEvan what version are you on? It seems fixed in v5.2.8

@SellersEvan
Copy link
Copy Markdown

@chukwumaokere Just updated and the issues seems to be resolved. Thanks! That's the first thing I should of check.

@kevinmcalear
Copy link
Copy Markdown

I'm having this exact same issue and had to patch using this type of fix

@github-actions
Copy link
Copy Markdown

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@magrinj
Copy link
Copy Markdown
Contributor Author

magrinj commented Apr 10, 2026

Seems to still occur regarding the comments

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]: getBoundingClientRect fallback missing typeof guard in useBoundingClientRect

4 participants