server-side rendering - window.addEventListener is not a function
- Dominant language
- JavaScript
- Stars
- 10.7k
- Forks
- 407
- PR merge metrics
- No merged PRs in 30d
Description
If you try to load Zdog in outside an browser-less environment like on server-side, you will likely run into an error
```
dragger.js:84 Uncaught TypeError: window.addEventListener is not a function
at Item.Dragger.dragStart (dragger.js:84)
at Item.Illustration.dragStart (illustration.js:232)
at Item.Dragger.onmousedown.Dragger.onpointerdown (dragger.js:73)
at Item.Dragger.handleEvent (dragger.js:67)
```
Zdog currently expects browser environment for things like `window` and `document`. My basic recommendation is to add a conditional to disable loading Zdog on the server, and enable it for the browser. I'm not a server-side rendering expert, so any guidance here on how to manage would be appreciated.
---
Add a 👍 reaction to this issue if you've ran into this issue so I know how prevalent this is.
Contributor guide
Research direction
Start by reproducing the server-side rendering failure and inspect dragger.js:84, illustration.js:232, and the related event-handling paths shown in the stack trace. Determine how Zdog should behave without browser globals, then verify that server-side loading avoids the error while browser interaction still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100