-
Notifications
You must be signed in to change notification settings - Fork 57
Studio: Update zod to v4 #2394
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
Studio: Update zod to v4 #2394
Conversation
|
For reference on changes: https://zod.dev/v4/changelog (if you want to double-check things) |
📊 Performance Test ResultsComparing 266f4b3 vs trunk site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change |
epeicher
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.
Thanks for upgrading this, Kat! I’ve done a smoke test on some parts of the application and haven’t found any issues, including nothing in the DevTools console.
I’ve left a comment about one change required for the new version, which should also fix the unit tests. Once that’s updated, this should be good to go.
Thanks for linking the changelog link, Kat! I have noticed that we may also want to update the @@ -44,9 +44,9 @@ export type ManagerMessagePayload = z.infer< typeof _managerMessagePayloadSchem
const managerMessageBase = z.object( { messageId: z.number() } );
export const managerMessageSchema = z.discriminatedUnion( 'topic', [
- managerMessageBase.merge( managerMessageStartServer ),
- managerMessageBase.merge( managerMessageRunBlueprint ),
- managerMessageBase.merge( managerMessageStopServer ),
+ managerMessageBase.extend( managerMessageStartServer.shape ),
+ managerMessageBase.extend( managerMessageRunBlueprint.shape ),
+ managerMessageBase.extend( managerMessageStopServer.shape ),
] );
export type ManagerMessage = z.infer< typeof managerMessageSchema >;also the following change in @@ -119,7 +119,7 @@ const wpcomPublicBaseQuery: BaseQueryFn<
}
};
-function parseResponse< TSchema extends z.ZodTypeAny >(
+function parseResponse< TSchema extends z.ZodType >(
response: unknown,
schema: TSchema
): z.infer< TSchema > { |
I applied your suggestions in 6848bf1 - please let me know what you think 🙇 |
ivan-ottinger
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 applied your suggestions in 6848bf1 - please let me know what you think 🙇
Looks good! Thanks for the update, Kat. I did not observe any other changes that would be missing.
| lastBumpStats: z | ||
| .record( z.string(), z.record( z.nativeEnum( StatsMetric ), z.number() ) ) | ||
| .loose() | ||
| .optional(), | ||
| lastBumpStats: z.record( z.string(), z.record( z.string(), z.number() ) ).optional(), |
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.
@katinthehatsite, how come the StatsMetric enum isn't included in the new schema?
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 it was mostly something that I overlooked during the update. I added a follow-up PR here: #2417 . I also noticed that there were more updates needed after the CLI dev branch was merged so I addressed these changes there as well.
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.
Actually I looked into it a bit more and ended up removing them even in the follow-up PR. Initially, I kept them but it required more code that seemed unnecessary. I think it is okay to remove it, and it feels like a more pragmatic choice. TypeScript already enforces type safety at compile-time where the data is created. Zod will validate the data structure (nested records with numbers) in this case and does not necessarily need to duplicate TypeScript's business logic validation of enum values.
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.
See #2417 (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 tried that option 😅 but ultimately, it did not seem to be the best one. I added some details here: #2417 (comment)
Related issues
Fixes STU-517
Proposed Changes
This PR updates to Zod v4 and resolves incompatibility issues.
Testing Instructions
npm start, test the app holistically, especially around actions that make API requests, and confirm there are no errors in the consolePre-merge Checklist