p5.js icon indicating copy to clipboard operation
p5.js copied to clipboard

Upgrade FES from Zod 3 to Zod 4?

Open davepagurek opened this issue 7 months ago • 9 comments

Increasing access

Apparently Zod 4 has some big performance bumps. Since FES uses Zod for parameter checking, and a big reason for people to turn FES off is to squeeze out more performance, maybe it'll let people use FES for longer before having to do so?

Most appropriate sub-area of p5.js?

  • [ ] Accessibility
  • [ ] Color
  • [ ] Core/Environment/Rendering
  • [ ] Data
  • [ ] DOM
  • [ ] Events
  • [ ] Image
  • [ ] IO
  • [ ] Math
  • [ ] Typography
  • [ ] Utilities
  • [ ] WebGL
  • [ ] Build process
  • [ ] Unit testing
  • [ ] Internationalization
  • [x] Friendly errors
  • [ ] Other (specify if possible)

Feature enhancement details

I'm not sure if there are any breaking changes that affect us, which could make it less of a straight win. But we use a fairly small set of what Zod can do, so this might be a quick change?

davepagurek avatar May 19 '25 19:05 davepagurek

@davepagurek can I work on this issue!!

madhav2348 avatar May 24 '25 05:05 madhav2348

Thanks @madhav2348 ! Let me know if you run into any issues in the process.

davepagurek avatar May 24 '25 15:05 davepagurek

Thank you for your support, I definitely let you know

madhav2348 avatar May 24 '25 18:05 madhav2348

hi @davepagurek I was making some changes using zod/v4 and started with browser_errors.js and file_errors.js but during testing in Running "browserify" task file_errors.js I got his error

Couldn't evaluate i18next key. You should either make the key evaluable or skip the line using a skip comment (/* i18next-extract-disable-line */ or /* i18next-extract-disable-next-line */). 

which i resolved by using skip comments , But this following error occurs even if I try to replace ES6 imports/exports with CommonJS even after adding "sourceType":"module" in package.json

Fatal error: 'import' and 'export' may appear only with 'sourceType: module'

madhav2348 avatar May 25 '25 07:05 madhav2348

Hi @madhav2348, what version of node are you using? We were seeing some issues like this before, but only on node 18 and under. Could you try 20 or higher if you haven't already?

davepagurek avatar May 26 '25 12:05 davepagurek

I checked my node version which is v22.14.0

madhav2348 avatar May 26 '25 14:05 madhav2348

Also I think you probably don't need to update browser_errors.js and file_errors.js, we're using zod in src/core/friendly_errors/param_validator.js here: https://github.com/processing/p5.js/blob/d51184b5598e4d51dca12905aeb3387b2e6a95bf/src/core/friendly_errors/param_validator.js#L6

After upgrading the zod version via npm upgrade zod@^3.25.0, what happens when you change that line above to import { z } from "zod/v4";?

Also, do you get the same error on a fresh clone of p5 on the dev-2.0 branch without adjusting the zod version at all?

davepagurek avatar May 26 '25 14:05 davepagurek

My mistake, I didn't realise that I was in the main branch , so now I switch to dev-2.0

Although I went through the migration docs, there are no major changes, just deprecation of _def in line 356 and line 360

And many test cases fail because optional() :

[TypeError: schema.optional is not a function] its type.
[param_validator.js, line 234] "optional" could not be called as a function.
Verify whether "schema" has "optional" in it and check the spelling, letter-casing (JavaScript is case-sensitive) and its type.

and

⚠️ [WEBDRIVERIO DEPRECATION NOTICE] The "switchToFrame" command is deprecated and we encourage everyone to use `switchFrame` instead for switching into frames. Read more about this command at https://webdriver.io/docs/api/browser/switchFrame.

I'll try to resolve it and make a PR soon

Thankyou

madhav2348 avatar May 27 '25 15:05 madhav2348

hey @davepagurek

Should I update the test cases or trim the message to get the expected results ?

Although I went through the migration docs, there are no major changes, just deprecation of _def in line 356 and line 360

In Zod 4, I thought there were minor changes, but most of the test cases are failing

  • with zod 4 error messages are more elaborate

(zod 3) Expected : "🌸 p5.js says: Expected number at the sixth parameter, but received undefined in p5.arc()."
(zod 4) Received : "🌸 p5.js says: Expected number at the sixth parameter, but received Invalid input: expected number, received undefined in p5.arc()."



(zod 3) Expected: "🌸 p5.js says: Expected constant (please refer to documentation for allowed values) at the first parameter, but received 100 in p5.blendMode()."
(zod 4) Received: "🌸 p5.js says: Expected constant (please refer to documentation for allowed values) at the first parameter, but received Invalid input: expected "source-over" in p5.blendMode()."

madhav2348 avatar May 30 '25 18:05 madhav2348

Resolved in #7872

limzykenneth avatar Jul 29 '25 13:07 limzykenneth