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

perf: improve ssr performance #1068

Merged
merged 5 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'

export default {
created () {
if (this.$ssrContext) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this file has been removed for now since we deprecated smooth scroll.

return;
}

this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
this.$vuepress.$set('contentMounted', true)

Expand Down Expand Up @@ -33,11 +37,15 @@ export default {
watch: {
'$route.path' () {
this.$vuepress.$set('contentMounted', false)
this.$smoothScroll.destroy()
if (!this.$ssrContext) {
this.$smoothScroll.destroy()
}
}
},

beforeDestroy () {
this.$smoothScroll.destroy()
if (!this.$ssrContext) {
this.$smoothScroll.destroy()
}
}
}
16 changes: 8 additions & 8 deletions packages/@vuepress/theme-default/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,11 @@ export function resolvePage (pages, rawPath, base) {
rawPath = resolvePath(rawPath, base)
}
const path = normalize(rawPath)
for (let i = 0; i < pages.length; i++) {
if (normalize(pages[i].regularPath) === path) {
return Object.assign({}, pages[i], {
type: 'page',
path: ensureExt(pages[i].path)
})
}
if (path in pages) {
Copy link

@sullivanpt sullivanpt Dec 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the function signature but doesn't update all the callers. resolvePage is also called from the default theme. See vuepress/packages/@vuepress/theme-default/components/Page.vue computed.prev. which is now broken and gives an error when trying to use frontmatter prev / next links. See #1140 for a primitive fix. Thanks.

return Object.assign({}, pages[path], {
type: 'page',
path: ensureExt(pages[path].path)
})
}
console.error(`[vuepress] No matching page found for sidebar item "${rawPath}"`)
return {}
Expand Down Expand Up @@ -128,12 +126,14 @@ export function resolveSidebarItems (page, regularPath, site, localePath) {
}

const sidebarConfig = localeConfig.sidebar || themeConfig.sidebar
let normalizedPagesMap = {}
pages.forEach(page => normalizedPagesMap[normalize(page.regularPath)] = page);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe following style would be more refreshing:

const normalizedPagesMap = pages.reduce((map, page) => map[normalize(page.regularPath)] = page, {})

if (!sidebarConfig) {
return []
} else {
const { base, config } = resolveMatchingConfig(regularPath, sidebarConfig)
return config
? config.map(item => resolveItem(item, pages, base))
? config.map(item => resolveItem(item, normalizedPagesMap, base))
: []
}
}
Expand Down