Skip to content

Conversation

yogan
Copy link
Contributor

@yogan yogan commented Oct 5, 2025

See: https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event#event_type

Using the correct type should get rid of Zod printing errors in the console when window resize events are triggered:

Zod error object {code: "custom", message: "Expected a UIEvent", …}
p5.js says:  in windowResized().

Resolves #8128

Changes:
Put correct event type in docstring of windowResized

PR Checklist

See: https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event#event_type

Using the correct type should get rid of Zod printing errors in the
console when window resize events are triggered:

    Zod error object {code: "custom", message: "Expected a UIEvent", …}
    p5.js says:  in windowResized().
Copy link

welcome bot commented Oct 5, 2025

🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors!
🤔 Please ensure that your PR links to an issue, which has been approved for work by a maintainer; otherwise, there might already be someone working on it, or still ongoing discussion about implementation. You are welcome to join the discussion in an Issue if you're not sure!
🌸 Once your PR is merged, be sure to add yourself to the list of contributors on the readme page !

Thank You!

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Btw, I was unable to reproduce this issue. Can you provide me the full sketch what you were trying to use which shows zod errors?

Also, in the issue you mentioned it gives errors in 2.0.5 version but for 2.x versions we are working on dev-2.0 branch. If the issue persist in both versions, it would be nice to open-up a followup PR for dev-2.0 branch as well.

Apart from all, taking reference from MDN docs, resize-window generic type is Event hence it should be Event instead of UIEvent which looks correct. Thanks for working on this.

@aidanwyber
Copy link

@perminder-17 I've also been getting this error
image
Thank you @yogan for fixing it!

@yogan
Copy link
Contributor Author

yogan commented Oct 6, 2025

@perminder-17 here is an example sketch that throws the error on resize: https://github.com/yogan/p5js-creative-coding/blob/main/src/sketches/sketch1.ts#L41 - setup() and draw() are not really relevant, it is sufficient to have this very common pattern:

	p.windowResized = () => {
		p.resizeCanvas(p.windowWidth, p.windowHeight)
	}

The error looks exactly like the screenshot from @aidanwyber.

Thanks for pointing out the dev-2.0 branch, I'll create a separate PR there as well.

@yogan
Copy link
Contributor Author

yogan commented Oct 6, 2025

I've just noticed that the type is already correct on the dev-2.0 branch:
https://github.com/processing/p5.js/blob/dev-2.0/src/core/environment.js#L731
This might explain why @perminder-17 can't reproduce the error.

Note that when I specified that I'm using v2.0.5, I was referring to the npm version, I'm using p5js as a package in a Vite project.
Not sure how the npm release process works, but looking into the code in my node_modules there is definitely the wrong type there.

Copy link
Collaborator

@perminder-17 perminder-17 left a comment

Choose a reason for hiding this comment

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

Idk, i was testing it in dev-2.0 since in the issue it was written:

p5.js version

2.0.5

Anyways, thanks for fixing this.

@perminder-17 perminder-17 merged commit 9d05158 into processing:main Oct 7, 2025
2 checks passed
@yogan yogan deleted the fix/window-resized-param-type branch October 7, 2025 11:04
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

Successfully merging this pull request may close these issues.

Zod error "expected UIEvent" in windowResized parameter validation
3 participants