From 9523d3c70dad4a9732157a40bdcad3ea4881cffc Mon Sep 17 00:00:00 2001 From: Avindra Goolcharan Date: Wed, 13 Nov 2024 17:25:59 -0500 Subject: [PATCH 1/2] gotchas.md: remove typeof window gotcha Deno since version 2 has erased the `window` global. https://deno.com/blog/v2.0-release-candidate#changes-to-global-variables --- docs/guides/gotchas.md | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/docs/guides/gotchas.md b/docs/guides/gotchas.md index 2e7ae4b208c..0b5e9f45171 100644 --- a/docs/guides/gotchas.md +++ b/docs/guides/gotchas.md @@ -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: From a7c24e101514bfde9be8f64c57bb24e3900d06b0 Mon Sep 17 00:00:00 2001 From: Avindra Goolcharan Date: Wed, 13 Nov 2024 17:28:14 -0500 Subject: [PATCH 2/2] add @avindra as contributer --- contributors.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.yml b/contributors.yml index c11fb3b3030..8ee508fe9d3 100644 --- a/contributors.yml +++ b/contributors.yml @@ -69,6 +69,7 @@ - atesgoral - athongsavath - AustinGil +- avindra - awthwathje - axel-habermaier - baby230211