Skip to content

Conversation

@katinthehatsite
Copy link
Contributor

@katinthehatsite katinthehatsite commented Jan 14, 2026

Related issues

Fixes STU-517

Proposed Changes

This PR updates to Zod v4 and resolves incompatibility issues.

Testing Instructions

  • Confirm that all the checks pass (I also triggered builds for this just in case and everything went through)
  • Visual review should suffice
  • Additionally, pull the changes from this branch, start the app with npm start, test the app holistically, especially around actions that make API requests, and confirm there are no errors in the console

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@katinthehatsite katinthehatsite self-assigned this Jan 14, 2026
@katinthehatsite katinthehatsite marked this pull request as draft January 14, 2026 14:12
@katinthehatsite katinthehatsite marked this pull request as ready for review January 14, 2026 18:34
@katinthehatsite katinthehatsite requested a review from a team January 14, 2026 18:35
@katinthehatsite
Copy link
Contributor Author

katinthehatsite commented Jan 14, 2026

For reference on changes: https://zod.dev/v4/changelog (if you want to double-check things)

@wpmobilebot
Copy link

wpmobilebot commented Jan 15, 2026

📊 Performance Test Results

Comparing 266f4b3 vs trunk

site-editor

Metric trunk 266f4b3 Diff Change
load 2924.00 ms 2936.00 ms +12.00 ms 🔴 0.4%

site-startup

Metric trunk 266f4b3 Diff Change
siteCreation 8103.00 ms 8070.00 ms -33.00 ms 🟢 -0.4%
siteStartup 3948.00 ms 3936.00 ms -12.00 ms 🟢 -0.3%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change

Copy link
Contributor

@epeicher epeicher left a 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.

@ivan-ottinger
Copy link
Contributor

For reference on changes: https://zod.dev/v4/changelog (if you want to double-check things)

Thanks for linking the changelog link, Kat!

I have noticed that we may also want to update the .merge in cli/lib/types/wordpress-server-ipc.ts:

@@ -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 src/stores/wpcom-api.ts:

@@ -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 > {

@katinthehatsite
Copy link
Contributor Author

I have noticed that we may also want to update the .merge in cli/lib/types/wordpress-server-ipc.ts:

I applied your suggestions in 6848bf1 - please let me know what you think 🙇

@ivan-ottinger ivan-ottinger self-requested a review January 19, 2026 09:02
Copy link
Contributor

@ivan-ottinger ivan-ottinger left a 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.

@katinthehatsite katinthehatsite merged commit 82dd02c into trunk Jan 19, 2026
9 checks passed
@katinthehatsite katinthehatsite deleted the fix/migrate-to-zod-v4 branch January 19, 2026 09:45
Comment on lines -49 to +48
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(),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

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)

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.

7 participants