Skip to content

Commit

Permalink
perf: await routeData promises in parallel (#5027)
Browse files Browse the repository at this point in the history
  • Loading branch information
manniL authored and clarkdo committed Feb 13, 2019
1 parent 176641f commit 0826d7e
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/vue-app/template/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 0826d7e

Please sign in to comment.