fix: generatedstate memory leak & bump ts query

This commit is contained in:
Michael H.
2026-08-29 12:26:46 +02:00
parent 1bee2f83d8
commit bcf469ef91
5 changed files with 37 additions and 24 deletions
+1 -1
View File
@@ -48,7 +48,7 @@
"@modrinth/ui": "workspace:*",
"@modrinth/utils": "workspace:*",
"@sentry/nuxt": "^10.33.0",
"@tanstack/vue-query": "5.90.7",
"@tanstack/vue-query": "5.101.4",
"@types/three": "^0.172.0",
"@vitejs/plugin-vue": "^6.0.3",
"@vue-email/components": "^0.0.21",
+14 -1
View File
@@ -1,5 +1,6 @@
import type { ISO3166, Labrinth } from '@modrinth/api-client'
import type { DisplayProjectType } from '@modrinth/utils'
import type { ShallowRef } from 'vue'
import {
apiUrl,
@@ -155,11 +156,23 @@ const generatedState = shallowRef<GeneratedState>(
}) as GeneratedState,
)
/**
* Non-reactive server-side view of the state above.
*
* `generatedState` lives for the lifetime of the isolate, so every per-request `computed()` that
* reads it registers a subscriber link on its dep. SSR never unmounts, so those links are never
* released, and each one pins the whole request graph that created it. The data is frozen and
* `setGameVersions` is client-only, so the server has nothing to react to.
*/
const serverGeneratedState = {
value: generatedState.value,
} as unknown as ShallowRef<GeneratedState>
/**
* Composable for accessing the globally used generated state.
* This includes both fetched data and runtime-defined constants.
*/
export const useGeneratedState = () => generatedState
export const useGeneratedState = () => (import.meta.server ? serverGeneratedState : generatedState)
/**
* Replaces the build-time game versions with a freshly fetched list. Client-only: mutating this