From 2b017af155bdc141b3ccd04f52975da5ba1b526d Mon Sep 17 00:00:00 2001 From: Brandon Blakeley Date: Fri, 31 Jul 2026 19:45:04 -0400 Subject: [PATCH] fix(qwik-router): use z.ZodType instead of removed z.Schema for zod 4 compatibility --- .changeset/router-zod-zodtype.md | 5 +++++ packages/docs/src/routes/api/qwik-router/api.json | 2 +- packages/docs/src/routes/api/qwik-router/index.mdx | 4 ++-- .../src/runtime/src/qwik-router.runtime.api.md | 4 ++-- packages/qwik-router/src/runtime/src/server-functions.ts | 6 +++--- packages/qwik-router/src/runtime/src/types.ts | 8 ++++---- 6 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 .changeset/router-zod-zodtype.md diff --git a/.changeset/router-zod-zodtype.md b/.changeset/router-zod-zodtype.md new file mode 100644 index 00000000000..577ef7eab74 --- /dev/null +++ b/.changeset/router-zod-zodtype.md @@ -0,0 +1,5 @@ +--- +'@qwik.dev/router': patch +--- + +`zod$` now detects schemas via `z.ZodType` instead of the zod-3-only `z.Schema` alias, fixing a server-side TypeError (and 500s on every zod$ action) when the router resolves zod 4 in hoisted installs. diff --git a/packages/docs/src/routes/api/qwik-router/api.json b/packages/docs/src/routes/api/qwik-router/api.json index e0eae118893..2e472a23b1d 100644 --- a/packages/docs/src/routes/api/qwik-router/api.json +++ b/packages/docs/src/routes/api/qwik-router/api.json @@ -1342,7 +1342,7 @@ } ], "kind": "TypeAlias", - "content": "```typescript\nexport type ZodConstructor = {\n (schema: T): ZodDataValidator>;\n (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator>;\n (schema: T): ZodDataValidator;\n (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator;\n};\n```", + "content": "```typescript\nexport type ZodConstructor = {\n (schema: T): ZodDataValidator>;\n (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator>;\n (schema: T): ZodDataValidator;\n (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator;\n};\n```", "editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-router/src/runtime/src/types.ts", "mdFile": "router.zodconstructor.md" } diff --git a/packages/docs/src/routes/api/qwik-router/index.mdx b/packages/docs/src/routes/api/qwik-router/index.mdx index 88b684cdb51..250bf0ca3c0 100644 --- a/packages/docs/src/routes/api/qwik-router/index.mdx +++ b/packages/docs/src/routes/api/qwik-router/index.mdx @@ -3144,8 +3144,8 @@ export type ZodConstructor = { ( schema: (zod: typeof z.z, ev: RequestEvent) => T, ): ZodDataValidator>; - (schema: T): ZodDataValidator; - ( + (schema: T): ZodDataValidator; + ( schema: (zod: typeof z.z, ev: RequestEvent) => T, ): ZodDataValidator; }; diff --git a/packages/qwik-router/src/runtime/src/qwik-router.runtime.api.md b/packages/qwik-router/src/runtime/src/qwik-router.runtime.api.md index 0934b305766..cb1c869737a 100644 --- a/packages/qwik-router/src/runtime/src/qwik-router.runtime.api.md +++ b/packages/qwik-router/src/runtime/src/qwik-router.runtime.api.md @@ -679,8 +679,8 @@ export const zod$: ZodConstructor; export type ZodConstructor = { (schema: T): ZodDataValidator>; (schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator>; - (schema: T): ZodDataValidator; - (schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator; + (schema: T): ZodDataValidator; + (schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator; }; // Warning: (ae-forgotten-export) The symbol "ZodConstructorQRL" needs to be exported by the entry point index.d.ts diff --git a/packages/qwik-router/src/runtime/src/server-functions.ts b/packages/qwik-router/src/runtime/src/server-functions.ts index a6d4ec90824..4b0a7435f1a 100644 --- a/packages/qwik-router/src/runtime/src/server-functions.ts +++ b/packages/qwik-router/src/runtime/src/server-functions.ts @@ -310,18 +310,18 @@ const flattenZodIssues = (issues: z.ZodIssue | z.ZodIssue[]) => { /** @internal */ export const zodQrl: ZodConstructorQRL = ( qrl: QRL< - z.ZodRawShape | z.Schema | ((z: typeof import('zod').z, ev: RequestEvent) => z.ZodRawShape) + z.ZodRawShape | z.ZodType | ((z: typeof import('zod').z, ev: RequestEvent) => z.ZodRawShape) > ): ZodDataValidator => { if (isServer) { return { __brand: 'zod', async validate(ev, inputData) { - const schema: z.Schema = await qrl.resolve().then((obj) => { + const schema: z.ZodType = await qrl.resolve().then((obj) => { if (typeof obj === 'function') { obj = obj(z, ev); } - if (obj instanceof z.Schema) { + if (obj instanceof z.ZodType) { return obj; } else { return z.object(obj); diff --git a/packages/qwik-router/src/runtime/src/types.ts b/packages/qwik-router/src/runtime/src/types.ts index 549b05cd63a..ba2bb65865f 100644 --- a/packages/qwik-router/src/runtime/src/types.ts +++ b/packages/qwik-router/src/runtime/src/types.ts @@ -1129,8 +1129,8 @@ export type ZodConstructor = { ( schema: (zod: typeof z.z, ev: RequestEvent) => T ): ZodDataValidator>; - (schema: T): ZodDataValidator; - (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator; + (schema: T): ZodDataValidator; + (schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator; }; /** @public */ @@ -1139,8 +1139,8 @@ export type ZodConstructorQRL = { ( schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T> ): ZodDataValidator>; - (schema: QRL): ZodDataValidator; - (schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T>): ZodDataValidator; + (schema: QRL): ZodDataValidator; + (schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T>): ZodDataValidator; }; /** @public */