Skip to content

bug(tanstack-react-query): mutationOptions doesn't contain keyPrefix #7369

@tmkx

Description

@tmkx

Provide environment information

System:
  OS: macOS 26.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 129.14 MB / 36.00 GB
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 24.4.1 - /Users/tmk/.local/share/mise/installs/node/24.4.1/bin/node
  npm: 11.4.2 - /Users/tmk/.local/share/mise/installs/node/24.4.1/bin/npm
  pnpm: 10.33.2 - /Users/tmk/.local/share/mise/installs/node/24.4.1/bin/pnpm
  bun: 1.3.13 - /opt/homebrew/bin/bun
  Deno: 2.7.14 - /opt/homebrew/bin/deno
Browsers:
  Chrome: 147.0.7727.138
  Safari: 26.4
npmPackages:
  @tanstack/react-query: ^5.100.9 => 5.100.9
  @trpc/client: ^11.17.0 => 11.17.0
  @trpc/server: ^11.17.0 => 11.17.0
  typescript: ^6.0.3 => 6.0.3

Describe the bug

mutationOptions().mutationKey doesn't contain keyPrefix

Link to reproduction

none

To reproduce

import { QueryClient } from '@tanstack/query-core';
import { createTRPCClient } from '@trpc/client';
import { initTRPC } from '@trpc/server';
import { createTRPCOptionsProxy } from '@trpc/tanstack-react-query';

const t = initTRPC.create({
  isServer: true,
});

const appRouter = t.router({
  foo: t.router({
    bar: t.procedure.mutation(() => {
      return 'hello';
    }),
  }),
});

type AppRouter = typeof appRouter;

const trpcClient = createTRPCClient<AppRouter>({
  links: [],
});

export const trpc = createTRPCOptionsProxy<AppRouter, { keyPrefix: true }>({
  client: trpcClient,
  queryClient: new QueryClient(),
  keyPrefix: 'ns',
});

console.log(trpc.foo.bar.mutationKey()); // [ [ 'ns' ], [ 'foo', 'bar' ] ] ✅
console.log(trpc.foo.bar.mutationOptions().mutationKey); // [ [ 'foo', 'bar' ] ] ❌

Additional information

No response

👨‍👧‍👦 Contributing

  • 🙋‍♂️ Yes, I'd be down to file a PR fixing this bug!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions