`pnpm create @tanstack/start@latest` configures tRPC incorrectly #271
Send to my agentWhich 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#
Run
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
go to the
demo/trpc-todoroute 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>
);
}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.
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.
tannerlinsley closed this
Sign in to join this conversation.
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 / .