Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/router-zod-zodtype.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion packages/docs/src/routes/api/qwik-router/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@
}
],
"kind": "TypeAlias",
"content": "```typescript\nexport type ZodConstructor = {\n <T extends z.ZodRawShape>(schema: T): ZodDataValidator<z.ZodObject<T>>;\n <T extends z.ZodRawShape>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<z.ZodObject<T>>;\n <T extends z.Schema>(schema: T): ZodDataValidator<T>;\n <T extends z.Schema>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<T>;\n};\n```",
"content": "```typescript\nexport type ZodConstructor = {\n <T extends z.ZodRawShape>(schema: T): ZodDataValidator<z.ZodObject<T>>;\n <T extends z.ZodRawShape>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<z.ZodObject<T>>;\n <T extends z.ZodType>(schema: T): ZodDataValidator<T>;\n <T extends z.ZodType>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<T>;\n};\n```",
"editUrl": "https://github.com/QwikDev/qwik/tree/main/packages/qwik-router/src/runtime/src/types.ts",
"mdFile": "router.zodconstructor.md"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/docs/src/routes/api/qwik-router/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3144,8 +3144,8 @@ export type ZodConstructor = {
<T extends z.ZodRawShape>(
schema: (zod: typeof z.z, ev: RequestEvent) => T,
): ZodDataValidator<z.ZodObject<T>>;
<T extends z.Schema>(schema: T): ZodDataValidator<T>;
<T extends z.Schema>(
<T extends z.ZodType>(schema: T): ZodDataValidator<T>;
<T extends z.ZodType>(
schema: (zod: typeof z.z, ev: RequestEvent) => T,
): ZodDataValidator<T>;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ export const zod$: ZodConstructor;
export type ZodConstructor = {
<T extends z_2.ZodRawShape>(schema: T): ZodDataValidator<z_2.ZodObject<T>>;
<T extends z_2.ZodRawShape>(schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator<z_2.ZodObject<T>>;
<T extends z_2.Schema>(schema: T): ZodDataValidator<T>;
<T extends z_2.Schema>(schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator<T>;
<T extends z_2.ZodType>(schema: T): ZodDataValidator<T>;
<T extends z_2.ZodType>(schema: (zod: typeof z_2.z, ev: RequestEvent) => T): ZodDataValidator<T>;
};

// Warning: (ae-forgotten-export) The symbol "ZodConstructorQRL" needs to be exported by the entry point index.d.ts
Expand Down
6 changes: 3 additions & 3 deletions packages/qwik-router/src/runtime/src/server-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/qwik-router/src/runtime/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,8 +1129,8 @@ export type ZodConstructor = {
<T extends z.ZodRawShape>(
schema: (zod: typeof z.z, ev: RequestEvent) => T
): ZodDataValidator<z.ZodObject<T>>;
<T extends z.Schema>(schema: T): ZodDataValidator<T>;
<T extends z.Schema>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<T>;
<T extends z.ZodType>(schema: T): ZodDataValidator<T>;
<T extends z.ZodType>(schema: (zod: typeof z.z, ev: RequestEvent) => T): ZodDataValidator<T>;
};

/** @public */
Expand All @@ -1139,8 +1139,8 @@ export type ZodConstructorQRL = {
<T extends z.ZodRawShape>(
schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T>
): ZodDataValidator<z.ZodObject<T>>;
<T extends z.Schema>(schema: QRL<T>): ZodDataValidator<T>;
<T extends z.Schema>(schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T>): ZodDataValidator<T>;
<T extends z.ZodType>(schema: QRL<T>): ZodDataValidator<T>;
<T extends z.ZodType>(schema: QRL<(zod: typeof z.z, ev: RequestEvent) => T>): ZodDataValidator<T>;
};

/** @public */
Expand Down
Loading