Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: isBrowser false when no document.createElement #11315

Open
mateusvahl opened this issue Feb 28, 2024 · 0 comments
Open

[Bug]: isBrowser false when no document.createElement #11315

mateusvahl opened this issue Feb 28, 2024 · 0 comments
Labels

Comments

@mateusvahl
Copy link

What version of React Router are you using?

6.22.2

Steps to Reproduce

I'm running react-router-dom in Shopify customer account ui environment

This runs on a webworker with a subset javascript API and no access to DOM APIs.

When using useFetcher() , the submit action was throwing an error saying:

router.fetch() was called during the server render, but it shouldn't be. You are likely calling a useFetcher() method in the body of your component. Try moving it to a useEffect or a callback.

After further investigation in the source code, I notice it was related to to isBrowser detection, which expects window.document.createElement !== "undefined" (false in my environment).

A workaround was define createElement before initialise the route, which fixes the detection.

self.document.createElement = () => {  /** empty **/ };

Let me me know if any additional details is needed.

Expected Behavior

isBrowser should not really on window.document.createElement

Actual Behavior

window.document.createElement is undefined, leading isBrowser to be considered false.

@mateusvahl mateusvahl added the bug label Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant