Skip to content

Fixes for server side usage#8357

Open
limzykenneth wants to merge 8 commits intoprocessing:dev-2.0from
limzykenneth:server-usage
Open

Fixes for server side usage#8357
limzykenneth wants to merge 8 commits intoprocessing:dev-2.0from
limzykenneth:server-usage

Conversation

@limzykenneth
Copy link
Member

Changes:
Mainly putting some of the references to window and document behind 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.

@limzykenneth
Copy link
Member Author

Put something simple together to test this as a proof of concept: https://github.com/limzykenneth/p5.term.js

@limzykenneth limzykenneth marked this pull request as ready for review February 8, 2026 22:27
@limzykenneth
Copy link
Member Author

@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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any implications to using document.documentElement.clientWidth rather than window.innerWidth?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ksen0 ksen0 added this to the 2.3 milestone Feb 11, 2026
@ksen0 ksen0 moved this to In Progress in p5.js 2.x 🌱🌳 Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants