Skip to content

Upgrade FES from Zod 3 to Zod 4? #7833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 of 17 tasks
davepagurek opened this issue May 19, 2025 · 9 comments
Open
1 of 17 tasks

Upgrade FES from Zod 3 to Zod 4? #7833

davepagurek opened this issue May 19, 2025 · 9 comments

Comments

@davepagurek
Copy link
Contributor

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
  • 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?

@madhav2348
Copy link

@davepagurek can I work on this issue!!

@davepagurek
Copy link
Contributor Author

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

@madhav2348
Copy link

Thank you for your support, I definitely let you know

@madhav2348
Copy link

madhav2348 commented May 25, 2025

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'

@davepagurek
Copy link
Contributor Author

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?

@madhav2348
Copy link

I checked my node version which is v22.14.0

@davepagurek
Copy link
Contributor Author

davepagurek commented May 26, 2025

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:

import * as z from 'zod';

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?

@madhav2348
Copy link

madhav2348 commented May 27, 2025

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
Copy link

madhav2348 commented May 30, 2025

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()."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

3 participants