-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add section on Zod 4 to v6 migration guide #12848
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
Conversation
Lunaria Status Overview🌕 This pull request will trigger status changes. Learn moreBy default, every PR changing files present in the Lunaria configuration's You can change this by adding one of the keywords present in the Tracked Files
Warnings reference
|
✅ Deploy Preview for astro-docs-2 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thanks, @matthewp ! Also checking that none of these examples here where we describe using Zod for content collections look outdated to you? (This whole section on "Defining the collection schema" including the subsections for defining data types and collection references): https://deploy-preview-12322--astro-docs-2.netlify.app/en/guides/content-collections/#defining-datatypes-with-zod We also do mention and show examples of Zod schemas on the actions page, but it's probably the two sections here about validation where we have text/examples that we should double check are still accurate for Zod 4: https://deploy-preview-12322--astro-docs-2.netlify.app/en/guides/actions/#using-validators-with-form-inputs Lastly, even though Zod's migration guide shows everything, I would suspect there would be some changes that are common that most people would have to make to content collections schemas that are worth showing here, a way of focusing their attention on things that they'd very likely have to deal with. Can you suggest what some of those might be? If for example there were one or two things ONLY thing that will affect the majority of people, but maybe that's all they need to do, it would be much better for us to show those here. If it would be possible to help a number of people avoid needing to go to Zod's guide at all, then we really should do that. |
|
In addition to what Sarah just said, I noticed another change in the implementation regarding the use of the -heroImage: image().optional(),
+heroImage: z.optional(image()),Does this mean that |
Yes, I wasn't sure if updating other docs was in scope for these PRs or not, since in the last one it was not. Happy to update other docs though, just tell me.
Not really, no. I can only say what was common in updating Astro itself, but I wouldn't presume that holds over to CC users. For example |
It should still be chainable, I'll check to confirm. |
|
Just noting that we're holding on this one as some aspects of the implementation PR might determine what kind of guidance is needed here! |
|
@sarah11918 Which aspects? So I can unblock if possible. |
|
@matthewp We were waiting on whether or not |
|
Seeing #12866 and that some of our Action code samples had to update makes me think that mentioning some of Zod's changes ourself is probably helpful. Expecially if people have followed our code examples, and we are updating examples in docs, that's probably a good indication of what's common enough to include as some additional helpful content. So, in the Actions guide, we saw our own examples update from
Presumably the |
|
I think what you mentioned could be the most commonly used. Except that, maybe customizing errors? For people using Zod on the client (e.g. a form) and having implemented i18n, they probably customized the error messages because every errors were in English in Zod 3. The And, yes, we should mention Actions schema in addition to content collections! |
|
Do I need to update the examples/docs in this PR to their proper v4 usage? |
|
Hi @matthewp , sorry there hasn't been a lot of direct actionable instructions on this PR as Armand and I have kind of been discussing what might need to be said! I have taken a quick look through all the content collections material we show and I think I only saw one stray So here's what you can do:
I think that's all we'll do for now. As we notice people trying the beta and maybe struggling with the upgrade on certain things, we might later decide to add more specific guidance here. |
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
Co-authored-by: Sarah Rainsberger <[email protected]>
|
(Note: I added a Zod link, but this PR might need to be updated to the v6 branch to have access to some of the most recent comment. I suspect that will fix any link issues!) |
I don't know anything about this, can you explain @ArmandPhilippot ? |
|
@matthewp I think it might in fact be anyone creating custom error messages (and, translated ones are just a special case)? Hideoo commented that this section of the Zod guide might affect a significant number of people: https://zod.dev/v4/changelog#changes-error-map-precedence Does that make sense/help? (Sorry, I'm not familiar with this myself, and am relying on y'all.) |
|
@sarah11918 I'm also not that familiar with this, which is partially why I've been hesitant to give too much direct advice on how to migrate Zod. In the case of the link, that's done internally inside of Astro when it validates the schema. How a user can have custom error messages in their schema; I don't know the answer to that. I think it might not be possible any more, but I could be wrong. |
|
Yeah, as Sarah said, it's not about repeating all Zod changes, but simply highlighting common use cases, and error customization could be one of them. Maybe something like: Zod has dropped support for a custom `errorsMap` which was useful to redefine or translate your error messages. Some other changes have been made to the way to customize the error messages, you might need to update your code:
```diff
-z.string().min(5, { message: "Too short." });
+z.string().min(5, { error: "Too short." });
``` |
|
That looks good, Armand! |
|
I took a pass at explaining the |
|
@matthewp I think the If you're happy with the content now, including all the suggestions, I think this is good to go! |
|
(Just resolved conflicts and updated branch) |
Co-authored-by: Sarah Rainsberger <[email protected]>
sarah11918
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to go! Can update branch and merge any time!
Description (required)
Adds Zod 4 under the "Dependency Upgrades" section.
Mostly just refers to the Zod 4's own migration guide.
Related issues & labels (optional)
For Astro version:
6.x. See astro PR #14956.