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

docs(guides/gotchas): remove typeof window gotcha #10225

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
- atesgoral
- athongsavath
- AustinGil
- avindra
- awthwathje
- axel-habermaier
- baby230211
Expand Down
24 changes: 0 additions & 24 deletions docs/guides/gotchas.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,6 @@ Rendering your app on the server and in the browser with React has some inherent

This document should help you get over these bumps.

## `typeof window` checks

Because the same JavaScript code can run in the browser as well as the server, sometimes you need to have a part of your code that only runs in one context or the other:

```ts bad
if (typeof window === "undefined") {
// running in a server environment
} else {
// running in a browser environment
}
```

This works fine in a Node.js environment, however, Deno actually supports `window`! So if you really want to check whether you're running in the browser, it's better to check for `document` instead:

```ts good
if (typeof document === "undefined") {
// running in a server environment
} else {
// running in a browser environment
}
```

This will work for all JS environments (Node.js, Deno, Workers, etc.).

## Browser extensions injecting code

You may run into this warning in the browser:
Expand Down