Skip to content

fix: add document existence check for bare React Native contexts#341

Open
atheck wants to merge 1 commit into
10play:mainfrom
atheck:fix/focus-listener-rn-context
Open

fix: add document existence check for bare React Native contexts#341
atheck wants to merge 1 commit into
10play:mainfrom
atheck:fix/focus-listener-rn-context

Conversation

@atheck

@atheck atheck commented Feb 11, 2026

Copy link
Copy Markdown

Fixes #339

  • Add hasDocument() type guard to check if we're in a browser/webview context
  • Only add focus/blur event listeners when document exists
  • Update isReactNativeContext check to handle bare RN (old/new arch) and Expo
  • Prevents "Cannot read property 'addEventListener' of undefined" error

I sucessfully tested it with a bare react-native project using the old architecture and the example project.

Fixes 10play#339

- Add hasDocument() type guard to check if we're in a browser/webview context
- Only add focus/blur event listeners when document exists
- Update isReactNativeContext check to handle bare RN (old/new arch) and Expo
- Prevents "Cannot read property 'addEventListener' of undefined" error

This ensures focusListener works correctly in:
- Expo environments
- Bare React Native (old architecture)
- Bare React Native (new architecture)
- Web/WebView environments

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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]: TypeError: Cannot read property 'addEventListener' of undefined

1 participant