Skip to content

Commit 3680c3a

Browse files
jherrbrenelz
andauthored
feat: ugrade query integration (#256)
feat: update query integration Co-authored-by: Brenley Dueck <[email protected]>
1 parent cc307ad commit 3680c3a

File tree

9 files changed

+36
-39
lines changed

9 files changed

+36
-39
lines changed

frameworks/react-cra/add-ons/start/assets/src/router.tsx.ejs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ export const getRouter = () => {
1818
routeTree,
1919
context: { ...rqContext },
2020
defaultPreload: "intent",
21-
Wrap: (props: { children: React.ReactNode }) => {
22-
return (
23-
<TanstackQuery.Provider {...rqContext}>
24-
{props.children}
25-
</TanstackQuery.Provider>
26-
);
27-
},
2821
})
2922
3023
setupRouterSsrQueryIntegration({router, queryClient: rqContext.queryClient})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is auto-generated. Do not edit manually.
22
// Generated from add-ons, examples, hosts, project, and toolchains directories
3-
export const contentChecksum = 'b722b3f8235cbf4618c508da1b499a8a6a583d8107eebeb9e2ffe19716ddc7e9'
3+
export const contentChecksum = '33ec3ec7dbdb94bb6ef6d8ba9831b43fba7f3d1f88a10408684e0ba39d282142'

frameworks/react-cra/tests/snapshots/react-cra/cr-ts-start-tanstack-query-npm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"/src/data/demo.punk-songs.ts": "import { createServerFn } from '@tanstack/react-start'\n\nexport const getPunkSongs = createServerFn({\n method: 'GET',\n}).handler(async () => [\n { id: 1, name: 'Teenage Dirtbag', artist: 'Wheatus' },\n { id: 2, name: 'Smells Like Teen Spirit', artist: 'Nirvana' },\n { id: 3, name: 'The Middle', artist: 'Jimmy Eat World' },\n { id: 4, name: 'My Own Worst Enemy', artist: 'Lit' },\n { id: 5, name: 'Fat Lip', artist: 'Sum 41' },\n { id: 6, name: 'All the Small Things', artist: 'blink-182' },\n { id: 7, name: 'Beverly Hills', artist: 'Weezer' },\n])\n",
1010
"/src/integrations/tanstack-query/devtools.tsx": "import { ReactQueryDevtoolsPanel } from '@tanstack/react-query-devtools'\n\nexport default {\n name: 'Tanstack Query',\n render: <ReactQueryDevtoolsPanel />,\n}\n",
1111
"/src/integrations/tanstack-query/root-provider.tsx": "import { QueryClient, QueryClientProvider } from '@tanstack/react-query'\n\nexport function getContext() {\n const queryClient = new QueryClient()\n return {\n queryClient,\n }\n}\n\nexport function Provider({\n children,\n queryClient,\n}: {\n children: React.ReactNode\n queryClient: QueryClient\n}) {\n return (\n <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>\n )\n}\n",
12-
"/src/router.tsx": "import { createRouter } from '@tanstack/react-router'\nimport { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'\nimport * as TanstackQuery from './integrations/tanstack-query/root-provider'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\n// Create a new router instance\nexport const getRouter = () => {\n const rqContext = TanstackQuery.getContext()\n\n const router = createRouter({\n routeTree,\n context: { ...rqContext },\n defaultPreload: 'intent',\n Wrap: (props: { children: React.ReactNode }) => {\n return (\n <TanstackQuery.Provider {...rqContext}>\n {props.children}\n </TanstackQuery.Provider>\n )\n },\n })\n\n setupRouterSsrQueryIntegration({ router, queryClient: rqContext.queryClient })\n\n return router\n}\n",
12+
"/src/router.tsx": "import { createRouter } from '@tanstack/react-router'\nimport { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query'\nimport * as TanstackQuery from './integrations/tanstack-query/root-provider'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\n// Create a new router instance\nexport const getRouter = () => {\n const rqContext = TanstackQuery.getContext()\n\n const router = createRouter({\n routeTree,\n context: { ...rqContext },\n defaultPreload: 'intent',\n })\n\n setupRouterSsrQueryIntegration({ router, queryClient: rqContext.queryClient })\n\n return router\n}\n",
1313
"/src/routes/__root.tsx": "import {\n HeadContent,\n Scripts,\n createRootRouteWithContext,\n} from '@tanstack/react-router'\nimport { TanStackRouterDevtoolsPanel } from '@tanstack/react-router-devtools'\nimport { TanStackDevtools } from '@tanstack/react-devtools'\n\nimport Header from '../components/Header'\n\nimport TanStackQueryDevtools from '../integrations/tanstack-query/devtools'\n\nimport appCss from '../styles.css?url'\n\nimport type { QueryClient } from '@tanstack/react-query'\n\ninterface MyRouterContext {\n queryClient: QueryClient\n}\n\nexport const Route = createRootRouteWithContext<MyRouterContext>()({\n head: () => ({\n meta: [\n {\n charSet: 'utf-8',\n },\n {\n name: 'viewport',\n content: 'width=device-width, initial-scale=1',\n },\n {\n title: 'TanStack Start Starter',\n },\n ],\n links: [\n {\n rel: 'stylesheet',\n href: appCss,\n },\n ],\n }),\n\n shellComponent: RootDocument,\n})\n\nfunction RootDocument({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <head>\n <HeadContent />\n </head>\n <body>\n <Header />\n {children}\n <TanStackDevtools\n config={{\n position: 'bottom-right',\n }}\n plugins={[\n {\n name: 'Tanstack Router',\n render: <TanStackRouterDevtoolsPanel />,\n },\n TanStackQueryDevtools,\n ]}\n />\n <Scripts />\n </body>\n </html>\n )\n}\n",
1414
"/src/routes/demo/api.names.ts": "import { createFileRoute } from '@tanstack/react-router'\nimport { json } from '@tanstack/react-start'\n\nexport const Route = createFileRoute('/demo/api/names')({\n server: {\n handlers: {\n GET: () => json(['Alice', 'Bob', 'Charlie']),\n },\n },\n})\n",
1515
"/src/routes/demo/api.tq-todos.ts": "import { createFileRoute } from '@tanstack/react-router'\n\nconst todos = [\n {\n id: 1,\n name: 'Buy groceries',\n },\n {\n id: 2,\n name: 'Buy mobile phone',\n },\n {\n id: 3,\n name: 'Buy laptop',\n },\n]\n\nexport const Route = createFileRoute('/demo/api/tq-todos')({\n server: {\n handlers: {\n GET: () => {\n return Response.json(todos)\n },\n POST: async ({ request }) => {\n const name = await request.json()\n const todo = {\n id: todos.length + 1,\n name,\n }\n todos.push(todo)\n return Response.json(todo)\n },\n },\n },\n})\n",
Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
11
import { createRouter } from '@tanstack/solid-router'
2-
2+
<% if (addOnEnabled['tanstack-query']) { %>
3+
import { setupRouterSsrQueryIntegration } from '@tanstack/solid-router-ssr-query'
4+
import { getContext } from "./integrations/tanstack-query/provider";
5+
<% } %>
36
// Import the generated route tree
47
import { routeTree } from './routeTree.gen'
58

69
// Create a new router instance
710
export const getRouter = () => {
11+
<% if (addOnEnabled['tanstack-query']) { %>
12+
const rqContext = getContext();
13+
14+
const router = createRouter({
15+
routeTree,
16+
context: { ...rqContext },
17+
defaultPreload: "intent",
18+
})
19+
20+
setupRouterSsrQueryIntegration({router, queryClient: rqContext.queryClient})
21+
<% } else { %>
822
const router = createRouter({
923
routeTree,
1024
scrollRestoration: true,
25+
defaultPreloadStaleTime: 0,
1126
})
12-
return router
27+
<% } %>
28+
29+
return router;
1330
}

frameworks/solid/add-ons/start/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@tanstack/solid-start": "^1.132.25",
99
"vite": "^7.1.7",
1010
"vite-tsconfig-paths": "^5.1.4",
11-
"lucide-solid": "^0.544.0"
11+
"lucide-solid": "^0.544.0",
12+
"@tanstack/solid-router-ssr-query": "^1.132.25"
1213
}
13-
}
14+
}
Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
1-
import { QueryClient, QueryClientProvider } from '@tanstack/solid-query'
1+
import { QueryClient } from '@tanstack/solid-query'
22

3-
import type { JSX } from 'solid-js'
4-
5-
const queryClient = new QueryClient()
6-
7-
export default function AppTanstackQueryProvider(props: {
8-
children: JSX.Element
9-
}) {
10-
return (
11-
<QueryClientProvider client={queryClient}>
12-
{props.children}
13-
</QueryClientProvider>
14-
)
15-
}
3+
export function getContext() {
4+
const queryClient = new QueryClient();
5+
return {
6+
queryClient
7+
};
8+
}

frameworks/solid/project/base/src/routes/__root.tsx.ejs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<% if (!fileRouter) { ignoreFile() } %>import { HeadContent, Outlet, Scripts, createRootRouteWithContext } from '@tanstack/solid-router'
2-
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'<% for(const integration of integrations.filter(i => i.type === 'layout' || i.type === 'provider')) { %>
3-
import <%= integration.jsName %> from "<%= relativePath(integration.path) %>";
4-
<% } %>
2+
import { TanStackRouterDevtools } from '@tanstack/solid-router-devtools'
3+
54
<% if (addOnEnabled['solid-ui']) { %>
65
import "@fontsource/inter"
76
<% } %>
@@ -37,9 +36,6 @@ function RootComponent() {
3736
<body>
3837
<HeadContent />
3938
<Suspense>
40-
<% for(const integration of integrations.filter(i => i.type === 'provider')) { %>
41-
<<%= integration.jsName %>>
42-
<% } %>
4339
<% if (addOns.length || integrations.length || routes.length) { %>
4440
<Header />
4541
<% } %>
@@ -48,9 +44,6 @@ function RootComponent() {
4844
<% for(const integration of integrations.filter(i => i.type === 'layout')) { %>
4945
<<%= integration.jsName %> />
5046
<% } %>
51-
<% for(const integration of integrations.filter(i => i.type === 'provider').reverse()) { %>
52-
</<%= integration.jsName %>>
53-
<% } %>
5447
</Suspense>
5548
<Scripts />
5649
</body>

frameworks/solid/src/checksum.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// This file is auto-generated. Do not edit manually.
22
// Generated from add-ons, examples, hosts, project, and toolchains directories
3-
export const contentChecksum = 'a13c68662e9a710c7d3339947e7e97cded66cc91a4a97f0f06a89c76b3a6f881'
3+
export const contentChecksum = '97450d3bd15410ec0fb6553e0b2709464dbef2b643f509e73ff124a3230f44c5'

0 commit comments

Comments
 (0)