From 93c4be2d286787e0d6522fa5bc7f5f437bc9eab5 Mon Sep 17 00:00:00 2001 From: taldy Date: Sun, 26 Mar 2017 17:54:27 +0300 Subject: [PATCH 1/5] Support other types of Promises returned by nuxtServerInit() --- lib/app/server.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/app/server.js b/lib/app/server.js index fa5cff0c75..f4b2ec16d4 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -81,7 +81,7 @@ export default context => { // nuxtServerInit <% if (store) { %> let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null) - if (!(promise instanceof Promise)) promise = Promise.resolve() + if (!promise || (!(promise instanceof Promise) && (promise && typeof promise.then !== 'function'))) promise = Promise.resolve() <% } else { %> let promise = Promise.resolve() <% } %> From c22b0b790b1d267f3eba0c07fc95caefe14b9a86 Mon Sep 17 00:00:00 2001 From: taldy Date: Thu, 6 Apr 2017 12:09:56 +0300 Subject: [PATCH 2/5] Simplify fix and cover other Promise checks --- lib/app/client.js | 4 ++-- lib/app/server.js | 2 +- lib/app/utils.js | 2 +- lib/utils.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/app/client.js b/lib/app/client.js index db3edeeb11..004271ff13 100644 --- a/lib/app/client.js +++ b/lib/app/client.js @@ -166,7 +166,7 @@ function render (to, from, next) { } if (Component.options.fetch) { var p = Component.options.fetch(context) - if (!(p instanceof Promise)) { p = Promise.resolve(p) } + if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { p = Promise.resolve(p) } <%= (loading ? 'p.then(() => this.$loading.increase && this.$loading.increase(30))' : '') %> promises.push(p) } @@ -318,7 +318,7 @@ function addHotReload ($component, depth) { // Call fetch() Component.options.fetch = Component.options.fetch || noopFetch let pFetch = Component.options.fetch(context) - if (!(pFetch instanceof Promise)) { pFetch = Promise.resolve(pFetch) } + if (!pFetch || (!(pFetch instanceof Promise) && (typeof pFetch.then !== 'function'))) { pFetch = Promise.resolve(pFetch) } <%= (loading ? 'pFetch.then(() => this.$loading.increase && this.$loading.increase(30))' : '') %> promises.push(pFetch) return Promise.all(promises) diff --git a/lib/app/server.js b/lib/app/server.js index f4b2ec16d4..5bf49aa877 100644 --- a/lib/app/server.js +++ b/lib/app/server.js @@ -81,7 +81,7 @@ export default context => { // nuxtServerInit <% if (store) { %> let promise = (store._actions && store._actions.nuxtServerInit ? store.dispatch('nuxtServerInit', omit(getContext(context), 'redirect', 'error')) : null) - if (!promise || (!(promise instanceof Promise) && (promise && typeof promise.then !== 'function'))) promise = Promise.resolve() + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) promise = Promise.resolve() <% } else { %> let promise = Promise.resolve() <% } %> diff --git a/lib/app/utils.js b/lib/app/utils.js index 013b3d4b29..e782671b75 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -84,7 +84,7 @@ export function promisify (fn, context) { } else { promise = fn(context) } - if (!(promise instanceof Promise)) { + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) promise = Promise.resolve(promise) } return promise diff --git a/lib/utils.js b/lib/utils.js index aedd6e9d55..185dc414f4 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -52,7 +52,7 @@ export function promisifyRoute (fn) { }) } let promise = fn() - if (!(promise instanceof Promise)) { + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) promise = Promise.resolve(promise) } return promise From 63f4f7449707699bea5897a294dee76587918a42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 6 Apr 2017 11:14:24 +0200 Subject: [PATCH 3/5] Fix syntax error --- lib/app/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/app/utils.js b/lib/app/utils.js index e782671b75..f6b34f0739 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -84,7 +84,7 @@ export function promisify (fn, context) { } else { promise = fn(context) } - if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) { promise = Promise.resolve(promise) } return promise From 7fb45da8d032c75ca610a20f6326ce4f18f00254 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Thu, 6 Apr 2017 11:14:43 +0200 Subject: [PATCH 4/5] Fix syntax error --- lib/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/utils.js b/lib/utils.js index 185dc414f4..edea410fdb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -52,7 +52,7 @@ export function promisifyRoute (fn) { }) } let promise = fn() - if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) { promise = Promise.resolve(promise) } return promise From 1ba4adca708870aad64a0d284ce8e87046dd9a9d Mon Sep 17 00:00:00 2001 From: taldy Date: Thu, 6 Apr 2017 12:18:27 +0300 Subject: [PATCH 5/5] Fix codestyle --- lib/app/utils.js | 2 +- lib/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/app/utils.js b/lib/app/utils.js index e782671b75..f6b34f0739 100644 --- a/lib/app/utils.js +++ b/lib/app/utils.js @@ -84,7 +84,7 @@ export function promisify (fn, context) { } else { promise = fn(context) } - if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) { promise = Promise.resolve(promise) } return promise diff --git a/lib/utils.js b/lib/utils.js index 185dc414f4..edea410fdb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -52,7 +52,7 @@ export function promisifyRoute (fn) { }) } let promise = fn() - if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) + if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) { promise = Promise.resolve(promise) } return promise