Skip to content
Source
Sign inSign up
TanStack/cli

`pnpm create @tanstack/start@latest` configures tRPC incorrectly #271

Send to my agent
Closedangel-3535(GitHub profile, opens in a new tab) opened this issue 3 comments

Which project does this relate to?

Create Tanstack App

Describe the bug

I ran pnpm create @tanstack/start@latest as instructed on tanstack.com/start/latest/docs/framework/react/quick-start When prompted to select add-ons I selected tRPC.

The tRPC demo route throws the following error: useTRPC() can only be used inside of a <TRPCProvider>

Your Example Website or App

N/A

Steps to Reproduce the Bug or Issue

  1. Run

  2. Choose: Would you like to use Tailwind CSS? │ Yes │ ◇ Select toolchain │ None │ ◇ Select deployment adapter │ Nitro (agnostic) │ ◇ What add-ons would you like for your project? │ tRPC │ ◇ Would you like any examples? │ none

  3. go to the demo/trpc-todo route and it has the following error: useTRPC() can only be used inside of a <TRPCProvider>

Expected behavior

The demo route should have no problem utilizing tRPC

Screenshots or Videos

No response

Platform

  • OS: macOS, Windows]
  • Router / Start Version: latest

Additional context

I got it to work by adding the provider from the integrations


import { Provider } from "@/integrations/tanstack-query/root-provider";
[...]
function RootDocument({ children }: { children: React.ReactNode }) {
  const { queryClient } = Route.useRouteContext();
  return (
    <html lang="en">
      <head>
        <HeadContent />
      </head>
      <body>
        <Provider queryClient={queryClient}>
        <Header />
        {children}
        <TanStackDevtools
          config={{
            position: "bottom-right",
          }}
          plugins={[
            {
              name: "Tanstack Router",
              render: <TanStackRouterDevtoolsPanel />,
            },
            TanStackQueryDevtools,
          ]}
        />
        </Provider>
        <Scripts />
      </body>
    </html>
  );
}
  1. Proposed fix is up in #356. Root cause was the React Query integration being tagged as instead of , so generated never wrapped the app in / .

  2. Correction: proposed fix is in PR #356. Root cause is that the React Query integration was tagged as root-provider instead of provider, so generated root route code did not wrap the app in TanStackQueryProvider/TRPCProvider.

  3. Fixed by PR #356. The React Query integration is now injected as a provider, so generated apps correctly wrap routes with TanStackQueryProvider/TRPCProvider and useTRPC no longer runs outside provider context.

  4. tannerlinsley closed this

Sign in to join this conversation.