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(client): avoid updating routeLocale #1253

Merged
merged 5 commits into from Feb 16, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 9 additions & 5 deletions packages/client/src/setupGlobalComputed.ts
@@ -1,4 +1,4 @@
import { type App, computed } from 'vue'
import { type App, computed, ref, watch } from 'vue'
import type { Router } from 'vue-router'
import {
type LayoutsRef,
Expand Down Expand Up @@ -58,13 +58,17 @@ export const setupGlobalComputed = (
router: Router,
clientConfigs: ClientConfig[]
): GlobalComputed => {
// create a manual computed route path, so that route hash changes won't trigger all downstream computed
const routePath = ref(router.currentRoute.value.path)
watch(
() => router.currentRoute.value.path,
(value) => (routePath.value = value)
)

// create global computed
const layouts = computed(() => resolvers.resolveLayouts(clientConfigs))
const routeLocale = computed(() =>
resolvers.resolveRouteLocale(
siteData.value.locales,
router.currentRoute.value.path
)
resolvers.resolveRouteLocale(siteData.value.locales, routePath.value)
)
const siteLocaleData = computed(() =>
resolvers.resolveSiteLocaleData(siteData.value, routeLocale.value)
Expand Down
8 changes: 1 addition & 7 deletions packages/client/src/setupUpdateHead.ts
@@ -1,7 +1,6 @@
import { isPlainObject, isString } from '@vuepress/shared'
import type { HeadConfig, VuepressSSRContext } from '@vuepress/shared'
import { onMounted, provide, ref, useSSRContext, watch } from 'vue'
import { useRoute } from 'vue-router'
import {
updateHeadSymbol,
usePageHead,
Expand All @@ -13,7 +12,6 @@ import type { UpdateHead } from './composables/index.js'
* Auto update head and provide as global util
*/
export const setupUpdateHead = (): void => {
const route = useRoute()
const head = usePageHead()
const lang = usePageLang()

Expand Down Expand Up @@ -64,11 +62,7 @@ export const setupUpdateHead = (): void => {
loadHead()
updateHead()
watch(
// when watching `head`, route hash changes will also trigger the watcher,
// causing unnecessary head updates
// so we watch `head` in dev mode to support hot-reload of `frontmatter.head`,
// and watch `route.path` in production mode to avoid extra updates
() => (__VUEPRESS_DEV__ ? head.value : route.path),
() => head.value,
() => updateHead()
)
})
Expand Down