Skip to content

fix(qwik-router): use z.ZodType instead of removed z.Schema for zod 4 compatibility - #8898

Open
blakeley wants to merge 1 commit into
QwikDev:mainfrom
blakeley:fix/router-zod-zodtype
Open

fix(qwik-router): use z.ZodType instead of removed z.Schema for zod 4 compatibility#8898
blakeley wants to merge 1 commit into
QwikDev:mainfrom
blakeley:fix/router-zod-zodtype

Conversation

@blakeley

@blakeley blakeley commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #8896

zodQrl decided whether a resolved value was already a schema with obj instanceof z.Schema. Schema was a zod-3-only alias for ZodType and was removed in zod 4, so as soon as the router's zod specifier resolves to a v4 copy — which is what happens in hoisted/deduped installs where the app depends on zod 4 — z.Schema is undefined and the instanceof throws TypeError: Right-hand side of 'instanceof' is not callable on the server, turning every zod$ action into a 500. This is not a version-mixing problem: the schema object and the instanceof check come from the same resolved zod module, the alias simply no longer exists. z.ZodType is exported by both zod 3 and zod 4 (in v3 Schema was literally an alias of it), so switching the runtime check — and the matching z.Schema type positions in ZodConstructor / ZodConstructorQRL — to z.ZodType is behaviour-preserving against the repo's pinned zod 3 and correct against zod 4. The API report and generated docs were regenerated with pnpm api.update; the only change there is z_2.Schemaz_2.ZodType.

Minimal reproduction: https://github.com/blakeley/zod4-zodschema-crash — it 500s on the pinned router build and passes with this patch applied, so the fix is verified empirically and not just by inspection.

Relationship to #8887 (zod export tree-shaking): orthogonal. That PR changes how zod is imported/re-exported for bundle size and keeps z.Schema as the detection mechanism, so it does not address this crash; the two should merge cleanly in either order, and if #8887 lands first the z.Schema reference it preserves still needs this change.

@blakeley
blakeley requested review from a team as code owners August 1, 2026 00:01
@changeset-bot

changeset-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2b017af

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@qwik.dev/router Patch
eslint-plugin-qwik Patch
@qwik.dev/core Patch
create-qwik Patch
@qwik.dev/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8898

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8898

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8898

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8898

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8898

@qwik.dev/devtools

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/devtools@8898

commit: 2b017af

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.

[🐞] v2: zod$ crashes when the router resolves zod 4 — z.Schema was removed (instanceof TypeError, every action 500s)

1 participant