refactor. 게임 데이터 초기화 개선

- LanguageSwitcher.vue에서 언어 전환 시 게임 데이터 즉시 갱신 로직 개선
- init-game-data.server.ts 파일 추가로 서버 사이드에서 게임 데이터 초기화 로직 구현
- app.vue에서 불필요한 게임 데이터 초기화 로직 제거
This commit is contained in:
clkim
2026-03-25 13:31:41 +09:00
parent 7a3be1754f
commit 4f83ae2311
3 changed files with 22 additions and 13 deletions

View File

@@ -1,13 +1,9 @@
<script setup lang="ts">
import { useNuxtApp } from 'nuxt/app'
const nuxtApp = useNuxtApp()
const { locale } = useI18n()
const gameDataStore = useGameDataStore()
const modalStore = useModalStore()
const scrollStore = useScrollStore()
const { setGameData } = gameDataStore
const { confirm, alert } = modalStore
const {
gameName,
@@ -95,13 +91,6 @@ const setupGameHead = () => {
}
}
if (import.meta.server) {
const gameData = nuxtApp.ssrContext?.event?.context?.gameData
if (gameData) {
setGameData(gameData)
}
}
setupGameHead()
let rafId: number | null = null

View File

@@ -233,10 +233,10 @@ const switchLanguage = async () => {
})
localeCookie.value = selectedLocale.value.toLowerCase()
// gameData 즉시 갱신 (1순위)
await loadGameData(selectedLocale.value)
// i18n locale 변경 (SPA)
await setLocale(selectedLocale.value as any)
// gameData가 언어별로 달라지는 영역(Header/GNB 등) 즉시 갱신
await loadGameData(selectedLocale.value)
// Nuxt SPA 라우팅으로 페이지 이동
await navigateTo(path)
}

View File

@@ -0,0 +1,20 @@
import type { GameDataValue } from '#layers/types/api/gameData'
export default defineNuxtPlugin({
name: 'hydrate-game-data',
dependsOn: ['pinia'],
setup(_nuxtApp) {
if (!import.meta.server) return
const event = useRequestEvent()
const gameData = (event?.context as { gameData?: GameDataValue })?.gameData
const currentLangCode = (event?.context as { currentLangCode?: string })
?.currentLangCode
if (!gameData) return
const gameDataStore = useGameDataStore()
gameDataStore.setCurrentLangCode(currentLangCode)
gameDataStore.setGameData(gameData)
},
})