Skip to content

Commit 6b0e96c

Browse files
committed
feat: tanstack as cross platform useAsyncData
1 parent 7bf2f33 commit 6b0e96c

File tree

7 files changed

+84
-7
lines changed

7 files changed

+84
-7
lines changed

apps/app-frontend/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
"test": "vue-tsc --noEmit"
1414
},
1515
"dependencies": {
16-
"@sfirew/minecraft-motd-parser": "^1.1.6",
1716
"@modrinth/assets": "workspace:*",
1817
"@modrinth/ui": "workspace:*",
1918
"@modrinth/utils": "workspace:*",
2019
"@sentry/vue": "^8.27.0",
20+
"@sfirew/minecraft-motd-parser": "^1.1.6",
21+
"@tanstack/vue-query": "^5.90.7",
2122
"@tauri-apps/api": "^2.5.0",
2223
"@tauri-apps/plugin-dialog": "^2.2.1",
2324
"@tauri-apps/plugin-http": "^2.5.0",
@@ -41,9 +42,9 @@
4142
"vue-virtual-scroller": "v2.0.0-beta.8"
4243
},
4344
"devDependencies": {
44-
"@modrinth/tooling-config": "workspace:*",
4545
"@eslint/compat": "^1.1.1",
4646
"@formatjs/cli": "^6.2.12",
47+
"@modrinth/tooling-config": "workspace:*",
4748
"@nuxt/eslint-config": "^0.5.6",
4849
"@taijased/vue-render-tracker": "^1.0.7",
4950
"@vitejs/plugin-vue": "^5.0.4",

apps/app-frontend/src/main.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'floating-vue/dist/style.css'
22

33
import * as Sentry from '@sentry/vue'
44
import { VueScanPlugin } from '@taijased/vue-render-tracker'
5+
import { VueQueryPlugin } from '@tanstack/vue-query'
56
import { createPlugin } from '@vintl/vintl/plugin'
67
import FloatingVue from 'floating-vue'
78
import { createPinia } from 'pinia'
@@ -45,6 +46,7 @@ Sentry.init({
4546
tracesSampleRate: 0.1,
4647
})
4748

49+
app.use(VueQueryPlugin)
4850
app.use(vueScan)
4951
app.use(router)
5052
app.use(pinia)

apps/frontend/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@
3838
"@formatjs/intl-localematcher": "^0.5.4",
3939
"@intercom/messenger-js-sdk": "^0.0.14",
4040
"@ltd/j-toml": "^1.38.0",
41+
"@modrinth/api-client": "workspace:*",
4142
"@modrinth/assets": "workspace:*",
4243
"@modrinth/blog": "workspace:*",
4344
"@modrinth/moderation": "workspace:*",
4445
"@modrinth/ui": "workspace:*",
4546
"@modrinth/utils": "workspace:*",
46-
"@modrinth/api-client": "workspace:*",
4747
"@pinia/nuxt": "^0.5.1",
48+
"@tanstack/vue-query": "^5.90.7",
4849
"@types/three": "^0.172.0",
4950
"@vintl/vintl": "^4.4.1",
5051
"@vitejs/plugin-vue": "^5.0.4",
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// https://tanstack.com/query/v5/docs/framework/vue/examples/nuxt3
2+
import type { DehydratedState, VueQueryPluginOptions } from '@tanstack/vue-query'
3+
import { QueryClient, VueQueryPlugin, dehydrate, hydrate } from '@tanstack/vue-query'
4+
5+
import { defineNuxtPlugin, useState } from '#imports'
6+
7+
export default defineNuxtPlugin((nuxt) => {
8+
const vueQueryState = useState<DehydratedState | null>('vue-query')
9+
10+
const queryClient = new QueryClient({
11+
defaultOptions: { queries: { staleTime: 5000 } },
12+
})
13+
const options: VueQueryPluginOptions = { queryClient }
14+
15+
nuxt.vueApp.use(VueQueryPlugin, options)
16+
17+
if (import.meta.server) {
18+
nuxt.hooks.hook('app:rendered', () => {
19+
vueQueryState.value = dehydrate(queryClient)
20+
})
21+
}
22+
23+
if (import.meta.client) {
24+
nuxt.hooks.hook('app:created', () => {
25+
hydrate(queryClient, vueQueryState.value)
26+
})
27+
}
28+
})

packages/ui/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"intl:extract": "formatjs extract \"src/**/*.{vue,ts,tsx,js,jsx,mts,cts,mjs,cjs}\" --ignore \"src/**/*.d.ts\" --out-file src/locales/en-US/index.json --preserve-whitespace"
2222
},
2323
"devDependencies": {
24-
"@modrinth/tooling-config": "workspace:*",
2524
"@formatjs/cli": "^6.2.12",
25+
"@modrinth/tooling-config": "workspace:*",
2626
"@stripe/stripe-js": "^7.3.1",
2727
"@vintl/unplugin": "^1.5.1",
2828
"@vintl/vintl": "^4.4.1",
@@ -37,9 +37,10 @@
3737
"@codemirror/language": "^6.9.3",
3838
"@codemirror/state": "^6.3.2",
3939
"@codemirror/view": "^6.22.1",
40+
"@modrinth/api-client": "workspace:*",
4041
"@modrinth/assets": "workspace:*",
4142
"@modrinth/utils": "workspace:*",
42-
"@modrinth/api-client": "workspace:*",
43+
"@tanstack/vue-query": "^5.90.7",
4344
"@tresjs/cientos": "^4.3.0",
4445
"@tresjs/core": "^4.3.4",
4546
"@tresjs/post-processing": "^2.4.0",

packages/ui/src/pages/route-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { resolve } from 'pathe'
1+
import { posix } from 'path'
22
import type { RouteRecordRaw } from 'vue-router'
33

44
interface NuxtPage {
@@ -36,7 +36,7 @@ export function createComponentResolver(baseDir: string) {
3636

3737
return {
3838
register(component: any, relativePath: string) {
39-
componentMap.set(component, resolve(baseDir, relativePath))
39+
componentMap.set(component, posix.resolve(baseDir, relativePath))
4040
},
4141
resolve(component: any): string {
4242
const path = componentMap.get(component)

pnpm-lock.yaml

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

0 commit comments

Comments
 (0)