perf: await routeData promises in parallel (#5027)

This commit is contained in:
Alexander Lichter 2019-02-13 14:37:12 +00:00 committed by Xin Du (Clark)
parent 176641f6cb
commit 0826d7e5fd

View File

@ -106,6 +106,9 @@ export function resolveRouteComponents(route) {
}
export async function getRouteData(route) {
if (!route) {
return
}
// Make sure the components are resolved (code-splitting)
await resolveRouteComponents(route)
// Send back a copy of route with meta based on Component definition
@ -188,19 +191,27 @@ export async function setContext(app, context) {
app.context.nuxtState = window.<%= globals.context %>
}
}
// Dynamic keys
const [currentRouteData, fromRouteData] = await Promise.all([
getRouteData(context.route),
getRouteData(context.from)
])
if (context.route) {
app.context.route = currentRouteData
}
if (context.from) {
app.context.from = fromRouteData
}
app.context.next = context.next
app.context._redirected = false
app.context._errored = false
app.context.isHMR = !!context.isHMR
if (context.route) {
app.context.route = await getRouteData(context.route)
}
app.context.params = app.context.route.params || {}
app.context.query = app.context.route.query || {}
if (context.from) {
app.context.from = await getRouteData(context.from)
}
}
export function middlewareSeries(promises, appContext) {