Skip to content

fix: check for document existence to support React Native#1152

Open
Br1an67 wants to merge 1 commit into
juliangarnier:masterfrom
Br1an67:fix/issue-1017-react-native-support
Open

fix: check for document existence to support React Native#1152
Br1an67 wants to merge 1 commit into
juliangarnier:masterfrom
Br1an67:fix/issue-1017-react-native-support

Conversation

@Br1an67

@Br1an67 Br1an67 commented Mar 8, 2026

Copy link
Copy Markdown

Fixes #1017

Summary

Fixed a ReferenceError that occurred when using anime.js in React Native environments. React Native has a window object but does not have a document object, which caused the library to throw "Property 'document' doesn't exist" error on import.

Changes

  • Added an explicit check for document existence in src/core/consts.js before accessing it
  • Changed export const doc = isBrowser ? document : null; to export const doc = isBrowser && typeof document !== 'undefined' ? document : null;

Testing

Verified that the JavaScript parses correctly. This is a minimal, surgical fix that only affects the document detection logic.

$ git diff --stat HEAD~1
src/core/consts.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

@Br1an67 Br1an67 force-pushed the fix/issue-1017-react-native-support branch from c9d8ca2 to 2da7595 Compare March 18, 2026 00:48
Comment thread src/core/consts.js

/** @type {Document|null} */
export const doc = isBrowser ? document : null;
export const doc = isBrowser && typeof document !== 'undefined' ? document : null;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isBrowser should return false in non browser environment. I don't like having this double check "is browser + document is undefined", can you update the isBrowser variable instead?

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.

[FEATURE] Support for react-native

2 participants