Skip to content

Zod v3 to v4 zCustomQuery migration breaking useQuery empty parameters #854

@adamk-au

Description

@adamk-au

When you migrated from:

import { zCustomQuery } from 'convex-helpers/server/zod';  // Zod v3

To:

import { zCustomQuery } from 'convex-helpers/server/zod4'; // Zod v4

Functions defined without args now require {} to be passed in useQuery.

Take this example:

// convex/users.ts (updated to use Zod 4)

// import { zCustomAction, zCustomMutation, zCustomQuery } from 'convex-helpers/server/zod';
import { zCustomAction, zCustomMutation, zCustomQuery } from 'convex-helpers/server/zod4';

export const zQuery = zCustomQuery(query, ...);

export const getUser= zQuery({
  args: {},
  handler: async (ctx) => {
    //...
  },
});
// ListUsers.tsx (frontend)

import { useQuery } from 'convex-helpers/react';

// works when using `zCustomQuery` from Zod v3, but not Zod4
const userQuery = useQuery(api.users.getUser);

// workaround for Zod4 is to add `{}` args
const userQuery = useQuery(api.users.getUser, {});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions