Skip to content

Commit 08977e3

Browse files
committed
vue-router-ssr-query
1 parent 722e85b commit 08977e3

File tree

9 files changed

+261
-0
lines changed

9 files changed

+261
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"@tanstack/router-ssr-query-core": "workspace:*",
101101
"@tanstack/react-router-ssr-query": "workspace:*",
102102
"@tanstack/solid-router-ssr-query": "workspace:*",
103+
"@tanstack/vue-router-ssr-query": "workspace:*",
103104
"@tanstack/zod-adapter": "workspace:*",
104105
"@tanstack/valibot-adapter": "workspace:*",
105106
"@tanstack/arktype-adapter": "workspace:*",
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# @tanstack/vue-router-ssr-query
2+
3+
SSR Query integration for TanStack Vue Router.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @tanstack/vue-router-ssr-query
9+
```
10+
11+
## Usage
12+
13+
```ts
14+
import { setupRouterSsrQueryIntegration } from '@tanstack/vue-router-ssr-query'
15+
import { QueryClient } from '@tanstack/vue-query'
16+
17+
const queryClient = new QueryClient()
18+
19+
setupRouterSsrQueryIntegration({
20+
router,
21+
queryClient,
22+
})
23+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import rootConfig from '../../eslint.config.js'
2+
3+
export default [
4+
...rootConfig,
5+
{
6+
files: ['src/**/*.{ts,tsx}', 'tests/**/*.{ts,tsx}'],
7+
plugins: {},
8+
rules: {
9+
'unused-imports/no-unused-vars': 'off',
10+
'@typescript-eslint/no-unnecessary-condition': 'off',
11+
},
12+
},
13+
]
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "@tanstack/vue-router-ssr-query",
3+
"version": "1.0.0",
4+
"description": "Modern and scalable routing for Vue applications",
5+
"author": "Tanner Linsley",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/TanStack/router.git",
10+
"directory": "packages/vue-router-ssr-query"
11+
},
12+
"homepage": "https://tanstack.com/router",
13+
"funding": {
14+
"type": "github",
15+
"url": "https://github.com/sponsors/tannerlinsley"
16+
},
17+
"keywords": [
18+
"vue",
19+
"location",
20+
"router",
21+
"routing",
22+
"async",
23+
"async router",
24+
"typescript"
25+
],
26+
"scripts": {
27+
"clean": "rimraf ./dist && rimraf ./coverage",
28+
"test:eslint": "eslint ./src",
29+
"test:types": "pnpm run \"/^test:types:ts[0-9]{2}$/\"",
30+
"test:types:ts54": "node ../../node_modules/typescript54/lib/tsc.js",
31+
"test:types:ts55": "node ../../node_modules/typescript55/lib/tsc.js",
32+
"test:types:ts56": "node ../../node_modules/typescript56/lib/tsc.js",
33+
"test:types:ts57": "node ../../node_modules/typescript57/lib/tsc.js",
34+
"test:types:ts58": "node ../../node_modules/typescript58/lib/tsc.js",
35+
"test:types:ts59": "tsc",
36+
"test:unit": "exit 0; vitest",
37+
"test:unit:dev": "pnpm run test:unit --watch",
38+
"test:build": "publint --strict && attw --ignore-rules no-resolution --pack .",
39+
"build": "vite build"
40+
},
41+
"type": "module",
42+
"types": "dist/esm/index.d.ts",
43+
"main": "dist/cjs/index.cjs",
44+
"module": "dist/esm/index.js",
45+
"exports": {
46+
".": {
47+
"import": {
48+
"types": "./dist/esm/index.d.ts",
49+
"default": "./dist/esm/index.js"
50+
},
51+
"require": {
52+
"types": "./dist/cjs/index.d.cts",
53+
"default": "./dist/cjs/index.cjs"
54+
}
55+
},
56+
"./package.json": "./package.json"
57+
},
58+
"sideEffects": false,
59+
"files": [
60+
"dist",
61+
"src"
62+
],
63+
"engines": {
64+
"node": ">=12"
65+
},
66+
"dependencies": {
67+
"@tanstack/router-ssr-query-core": "workspace:*"
68+
},
69+
"devDependencies": {
70+
"@tanstack/vue-query": "^5.92.0",
71+
"@tanstack/vue-router": "workspace:*",
72+
"@vitejs/plugin-vue-jsx": "^4.1.2",
73+
"vue": "^3.5.25"
74+
},
75+
"peerDependencies": {
76+
"@tanstack/query-core": ">=5.90.0",
77+
"@tanstack/vue-query": ">=5.90.0",
78+
"@tanstack/vue-router": ">=1.127.0",
79+
"vue": "^3.3.0"
80+
}
81+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import * as Vue from 'vue'
2+
import { setupCoreRouterSsrQueryIntegration } from '@tanstack/router-ssr-query-core'
3+
import type { RouterSsrQueryOptions } from '@tanstack/router-ssr-query-core'
4+
import type { AnyRouter } from '@tanstack/vue-router'
5+
import type { QueryClient } from '@tanstack/query-core'
6+
7+
// Vue Query uses this string as the injection key
8+
const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'
9+
10+
export type Options<TRouter extends AnyRouter> =
11+
RouterSsrQueryOptions<TRouter> & {
12+
wrapQueryClient?: boolean
13+
}
14+
15+
export function setupRouterSsrQueryIntegration<TRouter extends AnyRouter>(
16+
opts: Options<TRouter>,
17+
) {
18+
setupCoreRouterSsrQueryIntegration(opts)
19+
20+
if (opts.wrapQueryClient === false) {
21+
return
22+
}
23+
24+
const OGWrap =
25+
opts.router.options.Wrap ||
26+
((props: { children: any }) => props.children)
27+
28+
opts.router.options.Wrap = (props) => {
29+
return Vue.h(
30+
QueryClientProvider,
31+
{ client: opts.queryClient },
32+
() => Vue.h(OGWrap, null, () => props.children),
33+
)
34+
}
35+
}
36+
37+
const QueryClientProvider = Vue.defineComponent({
38+
name: 'QueryClientProvider',
39+
props: {
40+
client: {
41+
type: Object as () => QueryClient,
42+
required: true,
43+
},
44+
},
45+
setup(props, { slots }) {
46+
Vue.provide(VUE_QUERY_CLIENT, props.client)
47+
return () => slots.default?.()
48+
},
49+
})
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"jsx": "preserve",
5+
"jsxImportSource": "vue"
6+
},
7+
"include": ["src", "tests", "vite.config.ts", "eslint.config.ts"]
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { defineConfig, mergeConfig } from 'vitest/config'
2+
import { tanstackViteConfig } from '@tanstack/config/vite'
3+
import vueJsx from '@vitejs/plugin-vue-jsx'
4+
import packageJson from './package.json'
5+
import type { UserConfig } from 'vitest/config'
6+
7+
const config = defineConfig({
8+
plugins: [vueJsx()] as UserConfig['plugins'],
9+
test: {
10+
name: packageJson.name,
11+
dir: './tests',
12+
watch: false,
13+
environment: 'jsdom',
14+
typecheck: { enabled: true },
15+
},
16+
})
17+
18+
export default mergeConfig(
19+
config,
20+
tanstackViteConfig({
21+
entry: './src/index.tsx',
22+
srcDir: './src',
23+
}),
24+
)

pnpm-lock.yaml

Lines changed: 58 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/publish.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ await publish({
3636
name: '@tanstack/react-router-ssr-query',
3737
packageDir: 'packages/react-router-ssr-query',
3838
},
39+
{
40+
name: '@tanstack/vue-router-ssr-query',
41+
packageDir: 'packages/vue-router-ssr-query',
42+
},
3943
{
4044
name: '@tanstack/router-ssr-query-core',
4145
packageDir: 'packages/router-ssr-query-core',

0 commit comments

Comments
 (0)