Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-theme-data): fix theme-data sensitive with route object #1357

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 23 additions & 3 deletions ecosystem/plugin-theme-data/src/client/config.ts
@@ -1,6 +1,6 @@
import { setupDevtoolsPlugin } from '@vue/devtools-api'
import { defineClientConfig, routeLocaleSymbol } from '@vuepress/client'
import { computed } from 'vue'
import { ref, watch } from 'vue'
import {
resolveThemeLocaleData,
themeLocaleDataSymbol,
Expand All @@ -12,10 +12,30 @@ export default defineClientConfig({
// provide theme data & theme locale data
const themeData = useThemeData()
const routeLocale =
app._context.provides[routeLocaleSymbol as unknown as string]
const themeLocaleData = computed(() =>
app._context.provides[routeLocaleSymbol as unknown as symbol]

const themeLocaleData = ref(
resolveThemeLocaleData(themeData.value, routeLocale.value)
)
watch(
() => routeLocale.value,
(newRouteLocale, oldRouteLocale) => {
if (newRouteLocale !== oldRouteLocale)
themeLocaleData.value = resolveThemeLocaleData(
themeData.value,
routeLocale.value
)
}
)
watch(
() => themeData.value,
() => {
themeLocaleData.value = resolveThemeLocaleData(
themeData.value,
routeLocale.value
)
}
)
app.provide(themeLocaleDataSymbol, themeLocaleData)

Object.defineProperties(app.config.globalProperties, {
Expand Down