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

mount.js: Add undefined check before referencing window #1110

Open
pilotmoon opened this issue Nov 16, 2023 · 0 comments
Open

mount.js: Add undefined check before referencing window #1110

pilotmoon opened this issue Nov 16, 2023 · 0 comments

Comments

@pilotmoon
Copy link

pilotmoon commented Nov 16, 2023

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

This patch adds a small change to the if statement to check the window variable is not undefined before referencing it, following a similar pattern I've seen used in other projects. The reason for the change is that when building a server-side-rendered project using Vite, I get a "ReferenceError: window is not defined" on this line. It builds just fine with the modification in this patch.

Here is the diff that solved my problem:

diff --git a/node_modules/css-render/lib/mount.js b/node_modules/css-render/lib/mount.js
index e1523a0..a78142d 100644
--- a/node_modules/css-render/lib/mount.js
+++ b/node_modules/css-render/lib/mount.js
@@ -5,7 +5,7 @@ exports.mount = exports.unmount = exports.setCount = exports.getCount = void 0;
 const hash_1 = require("./hash");
 const render_1 = require("./render");
 const utils_1 = require("./utils");
-if (window) {
+if (typeof window !== "undefined" && window) {
     window.__cssrContext = {};
 }
 function getCount(el) {

This issue body was partially generated by patch-package.

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

No branches or pull requests

1 participant