Fixes for server side usage#8357
Conversation
Uses in node.js will need additional reimplementation of functionalities otherwise provided by window or document.
|
Put something simple together to test this as a proof of concept: https://github.com/limzykenneth/p5.term.js |
|
@ksen0 @davepagurek Do have a look when you have the time. This is all still a bit experimental in nature and probably need a bit more iteration in future PR. |
| (document.body && document.body.clientWidth) || | ||
| 0 | ||
| ); | ||
| return isBrowser ? document.documentElement.clientWidth : 0; |
There was a problem hiding this comment.
Are there any implications to using document.documentElement.clientWidth rather than window.innerWidth?
There was a problem hiding this comment.
window.innerWidth includes scrollbar while document.documentElement.clientWidth does not, which means the former will include areas that will be covered up by the scrollbar while the later will only be the visible area.
There was a problem hiding this comment.
It is kind of a different behavior although the previous behavior feels a bit undefined because it fallback on these different definition, at the same time I think document.documentElement.clientWidth is more likely to be the desired value. Can change it back though if there are edge cases that will be messed up by this.
There was a problem hiding this comment.
I think that makes sense then, we can just make sure we test this a bit when it's in an RC to see if there are any edge cases it breaks
There was a problem hiding this comment.
One thing I can think of is that if the sketch is created when the page does not have scroll bars but later on in the page lifetime it gained a scroll bar, that may be a bit unexpected since the value of document.documentElement.clientWidth changed in this case while window.innerWidth would stay the same. Not sure if it would be a problem though.
Changes:
Mainly putting some of the references to
windowanddocumentbehind checks that they exist so that they can run on a node.js runtime. Only two modules doesn't work so far which are FES and events. Events module is not expected to work since it relies on DOM event listeners, FES will need some changes for it to work.This is still a bit of a work in progress and should be merged at least after a round of dependency updates.