From 518692b2f44c4ef144d2adc12016d20e41d5deef Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Mon, 10 Jul 2017 04:27:50 +0430 Subject: [PATCH] chore: minor fixes --- lib/app/client.js | 10 ++++++++-- lib/app/index.js | 2 ++ lib/app/server.js | 6 +++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index f7ebf95759..96be5fd992 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -279,10 +279,14 @@ async function render (to, from, next) { // Call fetch(context) if (hasFetch) { - const promise = Component.options.fetch.call(_this, context).then(fetchResult => { + let p = Component.options.fetch.call(_this, context) + if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { + p = Promise.resolve(p) + } + p.then(fetchResult => { <% if(loading) { %>if(this.$loading.increase) this.$loading.increase(loadingIncrease)<% } %> }) - promises.push(promise) + promises.push(p) } return Promise.all(promises).then(() => { @@ -364,8 +368,10 @@ function fixPrepatch (to, ___) { } this.setLayout(layout) + <% if (isDev) { %> // Hot reloading setTimeout(() => hotReloadAPI(this), 100) + <% } %> }) } diff --git a/lib/app/index.js b/lib/app/index.js index 4f2ceaa11d..09a0cf44a1 100644 --- a/lib/app/index.js +++ b/lib/app/index.js @@ -116,6 +116,8 @@ async function createApp (ssrContext) { const _nuxt = this._nuxt || this.$options._nuxt _nuxt.dateErr = Date.now() _nuxt.err = err + console.error(err) + console.error('[nuxt] ' + err) return err } }, diff --git a/lib/app/server.js b/lib/app/server.js index ad5c190fe4..75b69718a4 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -81,12 +81,12 @@ export default async context => { // Resolve components let Components = [] try { - Components = await Promise.all(getMatchedComponents(router.match(context.url)).map((Component) => new Promise((resolve, reject) => { + Components = await Promise.all(getMatchedComponents(router.match(context.url)).map(Component => { if (typeof Component !== 'function' || Component.super === Vue) { - return resolve(sanitizeComponent(Component)) + return sanitizeComponent(Component) } return Component().then(Component => sanitizeComponent(Component)) - }))) + })) } catch (err) { // Throw back error to renderRoute() throw err