Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vuepress/core
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0.0-rc.6
Choose a base ref
...
head repository: vuepress/core
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v2.0.0-rc.7
Choose a head ref
  • 4 commits
  • 50 files changed
  • 2 contributors

Commits on Feb 5, 2024

  1. Copy the full SHA
    dcd9689 View commit details

Commits on Feb 6, 2024

  1. feat(client): add useClientData composable

    - optimize page component resolving
    - simplify global computed injection
    - improve code structure
    meteorlxy committed Feb 6, 2024
    Copy the full SHA
    37f646b View commit details
  2. Copy the full SHA
    d733357 View commit details
  3. build: publish v2.0.0-rc.7

    meteorlxy committed Feb 6, 2024
    Copy the full SHA
    7d9db9b View commit details
Showing with 278 additions and 491 deletions.
  1. +9 −0 CHANGELOG.md
  2. +1 −1 e2e/package.json
  3. +1 −1 package.json
  4. +1 −1 packages/bundler-vite/package.json
  5. +1 −1 packages/bundler-webpack/package.json
  6. +1 −1 packages/cli/package.json
  7. +1 −2 packages/client/package.json
  8. +5 −4 packages/client/src/app.ts
  9. +6 −5 packages/client/src/components/Content.ts
  10. +1 −1 packages/client/src/components/RouteLink.ts
  11. +21 −0 packages/client/src/composables/clientData.ts
  12. +49 −0 packages/client/src/composables/clientDataUtils.ts
  13. +2 −11 packages/client/src/composables/index.ts
  14. +0 −26 packages/client/src/composables/layouts.ts
  15. +0 −31 packages/client/src/composables/pageData.ts
  16. +0 −32 packages/client/src/composables/pageFrontmatter.ts
  17. +0 −31 packages/client/src/composables/pageHead.ts
  18. +0 −30 packages/client/src/composables/pageHeadTitle.ts
  19. +0 −30 packages/client/src/composables/pageLang.ts
  20. +0 −25 packages/client/src/composables/pageLayout.ts
  21. +0 −30 packages/client/src/composables/routeLocale.ts
  22. +0 −11 packages/client/src/composables/routes.ts
  23. +0 −31 packages/client/src/composables/siteLocaleData.ts
  24. +5 −0 packages/client/src/constants.ts
  25. +0 −8 packages/client/src/helpers/defineClientConfig.ts
  26. +0 −2 packages/client/src/helpers/index.ts
  27. +1 −3 packages/client/src/index.ts
  28. 0 packages/client/src/{router → internal}/routes.ts
  29. +1 −14 packages/client/src/{composables → internal}/siteData.ts
  30. +28 −49 packages/client/src/resolvers.ts
  31. +7 −7 packages/client/src/{ → router}/createVueRouter.ts
  32. +1 −1 packages/client/src/router/index.ts
  33. +1 −1 packages/client/src/router/resolveRoute.ts
  34. +1 −1 packages/client/src/router/resolveRoutePath.ts
  35. +45 −79 packages/client/src/setupGlobalComputed.ts
  36. +1 −2 packages/client/src/types/clientConfig.ts
  37. +64 −0 packages/client/src/types/clientData.ts
  38. +1 −1 packages/client/src/types/index.ts
  39. +0 −3 packages/client/src/types/layouts.ts
  40. +3 −3 packages/client/src/types/routes.ts
  41. +1 −0 packages/client/src/utils/index.ts
  42. 0 packages/client/src/{helpers → utils}/withBase.ts
  43. +1 −1 packages/core/package.json
  44. +1 −1 packages/markdown/package.json
  45. +1 −1 packages/shared/package.json
  46. +1 −1 packages/shared/src/types/site.ts
  47. +4 −6 packages/shared/src/utils/normalizeRoutePath.ts
  48. +1 −1 packages/utils/package.json
  49. +1 −1 packages/vuepress/package.json
  50. +9 −0 packages/vuepress/src/client.ts
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
# [2.0.0-rc.7](https://github.com/vuepress/core/compare/v2.0.0-rc.6...v2.0.0-rc.7) (2024-02-06)


### Features

* **client:** add useClientData composable ([37f646b](https://github.com/vuepress/core/commit/37f646bf700c38614914450244b77cb82eb8d50f))



# [2.0.0-rc.6](https://github.com/vuepress/core/compare/v2.0.0-rc.5...v2.0.0-rc.6) (2024-02-05)


2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/e2e",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"private": true,
"type": "module",
"scripts": {
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/monorepo",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"private": true,
"type": "module",
"scripts": {
2 changes: 1 addition & 1 deletion packages/bundler-vite/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/bundler-vite",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"description": "Bundler vite package of VuePress",
"keywords": [
"vuepress-bundler",
2 changes: 1 addition & 1 deletion packages/bundler-webpack/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/bundler-webpack",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"description": "Bundler webpack package of VuePress",
"keywords": [
"vuepress-bundler",
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/cli",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"description": "CLI package of VuePress",
"keywords": [
"vuepress",
3 changes: 1 addition & 2 deletions packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vuepress/client",
"version": "2.0.0-rc.6",
"version": "2.0.0-rc.7",
"description": "Client package of VuePress",
"keywords": [
"vuepress",
@@ -58,7 +58,6 @@
],
"external": [
"@internal/clientConfigs",
"@internal/layoutComponents",
"@internal/routes",
"@internal/siteData"
],
9 changes: 5 additions & 4 deletions packages/client/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { clientConfigs } from '@internal/clientConfigs'
import { createApp, createSSRApp, h } from 'vue'
import { siteData, usePageLayout } from './composables/index.js'
import { createVueRouter } from './createVueRouter.js'
import { usePageLayout } from './composables/index.js'
import { siteData } from './internal/siteData.js'
import { createVueRouter } from './router/createVueRouter.js'
import { setupGlobalComponents } from './setupGlobalComponents.js'
import { setupGlobalComputed } from './setupGlobalComputed.js'
import { setupUpdateHead } from './setupUpdateHead.js'
@@ -33,10 +34,10 @@ export const createVueApp: CreateVueAppFunction = async () => {
)

// get page layout
const layout = usePageLayout()
const pageLayout = usePageLayout()

// render layout and root components
return () => [h(layout.value), rootComponents]
return () => [h(pageLayout.value), rootComponents]
},
})

11 changes: 6 additions & 5 deletions packages/client/src/components/Content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { computed, defineAsyncComponent, defineComponent, h } from 'vue'
import { usePageData } from '../composables/index.js'
import { usePageComponent } from '../composables/index.js'
import { resolveRoute } from '../router/index.js'

/**
@@ -18,12 +18,13 @@ export const Content = defineComponent({
},

setup(props) {
const pageData = usePageData()
const pageComponent = computed(() => {
const route = resolveRoute(props.path || pageData.value.path)
const pageComponent = usePageComponent()
const ContentComponent = computed(() => {
if (!props.path) return pageComponent.value
const route = resolveRoute(props.path)
return defineAsyncComponent(() => route.loader().then(({ comp }) => comp))
})

return () => h(pageComponent.value)
return () => h(ContentComponent.value)
},
})
2 changes: 1 addition & 1 deletion packages/client/src/components/RouteLink.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { h } from 'vue'
import type { FunctionalComponent, HTMLAttributes, VNode } from 'vue'
import { useRouter } from 'vue-router'
import { withBase } from '../helpers/index.js'
import { resolveRoutePath } from '../router/index.js'
import { withBase } from '../utils/index.js'

/**
* Forked from https://github.com/vuejs/router/blob/941b2131e80550009e5221d4db9f366b1fea3fd5/packages/router/src/RouterLink.ts#L293
21 changes: 21 additions & 0 deletions packages/client/src/composables/clientData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { InjectionKey } from 'vue'
import { inject } from 'vue'
import type { ClientData } from '../types/index.js'

/**
* Injection key for client data
*/
export const clientDataSymbol: InjectionKey<ClientData> = Symbol(
__VUEPRESS_DEV__ ? 'clientData' : '',
)

/**
* Returns client data
*/
export const useClientData = (): ClientData => {
const clientData = inject(clientDataSymbol)
if (!clientData) {
throw new Error('useClientData() is called without provider.')
}
return clientData
}
49 changes: 49 additions & 0 deletions packages/client/src/composables/clientDataUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import type {
LayoutsRef,
PageComponentRef,
PageDataRef,
PageFrontmatterRef,
PageHeadRef,
PageLangRef,
PageLayoutRef,
RedirectsRef,
RouteLocaleRef,
RoutePathRef,
RoutesRef,
SiteDataRef,
SiteLocaleDataRef,
} from '../types/index.js'
import { useClientData } from './clientData.js'

export const useLayouts = (): LayoutsRef => useClientData().layouts

export const usePageComponent = (): PageComponentRef =>
useClientData().pageComponent

export const usePageData = <
T extends Record<any, any> = Record<never, never>,
>(): PageDataRef<T> => useClientData().pageData as PageDataRef<T>

export const usePageFrontmatter = <
T extends Record<any, any> = Record<string, unknown>,
>(): PageFrontmatterRef<T> =>
useClientData().pageFrontmatter as PageFrontmatterRef<T>

export const usePageHead = (): PageHeadRef => useClientData().pageHead

export const usePageLang = (): PageLangRef => useClientData().pageLang

export const usePageLayout = (): PageLayoutRef => useClientData().pageLayout

export const useRedirects = (): RedirectsRef => useClientData().redirects

export const useRouteLocale = (): RouteLocaleRef => useClientData().routeLocale

export const useRoutePath = (): RoutePathRef => useClientData().routePath

export const useRoutes = (): RoutesRef => useClientData().routes

export const useSiteData = (): SiteDataRef => useClientData().siteData

export const useSiteLocaleData = (): SiteLocaleDataRef =>
useClientData().siteLocaleData
13 changes: 2 additions & 11 deletions packages/client/src/composables/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
export * from './layouts.js'
export * from './pageData.js'
export * from './pageFrontmatter.js'
export * from './pageHead.js'
export * from './pageHeadTitle.js'
export * from './pageLang.js'
export * from './pageLayout.js'
export * from './routeLocale.js'
export * from './routes.js'
export * from './siteData.js'
export * from './siteLocaleData.js'
export * from './clientData.js'
export * from './clientDataUtils.js'
export * from './updateHead.js'
26 changes: 0 additions & 26 deletions packages/client/src/composables/layouts.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/client/src/composables/pageData.ts

This file was deleted.

32 changes: 0 additions & 32 deletions packages/client/src/composables/pageFrontmatter.ts

This file was deleted.

31 changes: 0 additions & 31 deletions packages/client/src/composables/pageHead.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/client/src/composables/pageHeadTitle.ts

This file was deleted.

Loading