catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optional jsdom

aight8 opened this issue · comments

Lot of projects use the window object to add events etc. to the DOM. When we have an option in the universal settings like "jsdom": true it could mimic the DOM in a certain way (it's then a fake DOM) to prevent errors.

var jsdom = require("jsdom").jsdom;
var doc = jsdom(markup, options);
var window = doc.defaultView;

https://github.com/tmpvar/jsdom

The document object holds en empty document of course but when it's available i prevents from errors.

When you don't want to implement this in this library maybe an hint would be nice to the users. Because it makes the development in react easier without caring about the availability of the window/document object etc.

Do you think using window is a good idea?
Show me an example.

I'm currently not at this stage but I plan ahead because I use this on some places / or 3rd party libs use it for some reason. Mostly the window object is not used at the page rendering w/o interaction (only in modals/waypoints etc.). I will revisit this issue when I have a working serverside rendered application :)

Yes, usually window is used either in componentDidMount or in some kind of event handler which aren't called on the server-side

Ah I didn't know that. 👍