Skip to content

Commit c5d0fa0

Browse files
committed
feat: make vue and basic server renderer compatible in pure js runtimes
1 parent 093673e commit c5d0fa0

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/platforms/web/runtime/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Vue.prototype.$mount = function (
4444

4545
// devtools global hook
4646
/* istanbul ignore next */
47-
setTimeout(() => {
47+
Vue.nextTick(() => {
4848
if (config.devtools) {
4949
if (devtools) {
5050
devtools.emit('init', Vue)

src/platforms/web/runtime/transition-util.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ if (hasTransition) {
5858
}
5959

6060
// binding to window is necessary to make hot reload work in IE in strict mode
61-
const raf = inBrowser && window.requestAnimationFrame
62-
? window.requestAnimationFrame.bind(window)
63-
: setTimeout
61+
const raf = inBrowser
62+
? window.requestAnimationFrame
63+
? window.requestAnimationFrame.bind(window)
64+
: setTimeout
65+
: /* istanbul ignore next */ fn => fn()
6466

6567
export function nextFrame (fn: Function) {
6668
raf(() => {

src/server/write.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
/* @flow */
22

33
const MAX_STACK_DEPTH = 1000
4+
const noop = _ => _
5+
6+
const defer = typeof process !== 'undefined' && process.nextTick
7+
? process.nextTick
8+
: typeof Promise !== 'undefined'
9+
? fn => Promise.resolve().then(fn)
10+
: typeof setTimeout !== 'undefined'
11+
? setTimeout
12+
: noop
13+
14+
if (defer === noop) {
15+
throw new Error(
16+
'Your JavaScript runtime does not support any asynchronous primitives ' +
17+
'that are required by vue-server-renderer. Please use a polyfill for ' +
18+
'either Promise or setTimeout.'
19+
)
20+
}
421

522
export function createWriteFunction (
623
write: (text: string, next: Function) => boolean,
@@ -14,7 +31,7 @@ export function createWriteFunction (
1431
const waitForNext = write(text, next)
1532
if (waitForNext !== true) {
1633
if (stackDepth >= MAX_STACK_DEPTH) {
17-
process.nextTick(() => {
34+
defer(() => {
1835
try { next() } catch (e) {
1936
onError(e)
2037
}

0 commit comments

Comments
 (0)