diff --git a/src/platforms/web/runtime/index.js b/src/platforms/web/runtime/index.js index eb8cd76ccda..3751acecc53 100644 --- a/src/platforms/web/runtime/index.js +++ b/src/platforms/web/runtime/index.js @@ -44,7 +44,7 @@ Vue.prototype.$mount = function ( // devtools global hook /* istanbul ignore next */ -setTimeout(() => { +Vue.nextTick(() => { if (config.devtools) { if (devtools) { devtools.emit('init', Vue) diff --git a/src/platforms/web/runtime/transition-util.js b/src/platforms/web/runtime/transition-util.js index 661f420d07f..47668f0c37d 100644 --- a/src/platforms/web/runtime/transition-util.js +++ b/src/platforms/web/runtime/transition-util.js @@ -58,9 +58,11 @@ if (hasTransition) { } // binding to window is necessary to make hot reload work in IE in strict mode -const raf = inBrowser && window.requestAnimationFrame - ? window.requestAnimationFrame.bind(window) - : setTimeout +const raf = inBrowser + ? window.requestAnimationFrame + ? window.requestAnimationFrame.bind(window) + : setTimeout + : /* istanbul ignore next */ fn => fn() export function nextFrame (fn: Function) { raf(() => { diff --git a/src/server/write.js b/src/server/write.js index 854d876b63e..e642081852c 100644 --- a/src/server/write.js +++ b/src/server/write.js @@ -1,6 +1,23 @@ /* @flow */ const MAX_STACK_DEPTH = 1000 +const noop = _ => _ + +const defer = typeof process !== 'undefined' && process.nextTick + ? process.nextTick + : typeof Promise !== 'undefined' + ? fn => Promise.resolve().then(fn) + : typeof setTimeout !== 'undefined' + ? setTimeout + : noop + +if (defer === noop) { + throw new Error( + 'Your JavaScript runtime does not support any asynchronous primitives ' + + 'that are required by vue-server-renderer. Please use a polyfill for ' + + 'either Promise or setTimeout.' + ) +} export function createWriteFunction ( write: (text: string, next: Function) => boolean, @@ -14,7 +31,7 @@ export function createWriteFunction ( const waitForNext = write(text, next) if (waitForNext !== true) { if (stackDepth >= MAX_STACK_DEPTH) { - process.nextTick(() => { + defer(() => { try { next() } catch (e) { onError(e) }