Skip to content
Permalink
Browse files
fix(ssr): adjust call stack size defer threshold
fix #8545
  • Loading branch information
yyx990803 committed Dec 2, 2018
1 parent 19c33a7 commit e4b1b57fd7117a19cdb376dcb156606e0cc32a94
Showing with 46 additions and 47 deletions.
  1. +45 鈭46 src/server/render-context.js
  2. +1 鈭1 src/server/write.js
@@ -66,55 +66,54 @@ export class RenderContext {
}

next () {
const lastState = this.renderStates[this.renderStates.length - 1]
if (isUndef(lastState)) {
return this.done()
}
/* eslint-disable no-case-declarations */
switch (lastState.type) {
case 'Element':
case 'Fragment':
const { children, total } = lastState
const rendered = lastState.rendered++
if (rendered < total) {
this.renderNode(children[rendered], false, this)
} else {
// eslint-disable-next-line
while (true) {
const lastState = this.renderStates[this.renderStates.length - 1]
if (isUndef(lastState)) {
return this.done()
}
/* eslint-disable no-case-declarations */
switch (lastState.type) {
case 'Element':
case 'Fragment':
const { children, total } = lastState
const rendered = lastState.rendered++
if (rendered < total) {
return this.renderNode(children[rendered], false, this)
} else {
this.renderStates.pop()
if (lastState.type === 'Element') {
return this.write(lastState.endTag, this.next)
}
}
break
case 'Component':
this.renderStates.pop()
if (lastState.type === 'Element') {
this.write(lastState.endTag, this.next)
this.activeInstance = lastState.prevActive
break
case 'ComponentWithCache':
this.renderStates.pop()
const { buffer, bufferIndex, componentBuffer, key } = lastState
const result = {
html: buffer[bufferIndex],
components: componentBuffer[bufferIndex]
}
this.cache.set(key, result)
if (bufferIndex === 0) {
// this is a top-level cached component,
// exit caching mode.
this.write.caching = false
} else {
this.next()
// parent component is also being cached,
// merge self into parent's result
buffer[bufferIndex - 1] += result.html
const prev = componentBuffer[bufferIndex - 1]
result.components.forEach(c => prev.add(c))
}
}
break
case 'Component':
this.renderStates.pop()
this.activeInstance = lastState.prevActive
this.next()
break
case 'ComponentWithCache':
this.renderStates.pop()
const { buffer, bufferIndex, componentBuffer, key } = lastState
const result = {
html: buffer[bufferIndex],
components: componentBuffer[bufferIndex]
}
this.cache.set(key, result)
if (bufferIndex === 0) {
// this is a top-level cached component,
// exit caching mode.
this.write.caching = false
} else {
// parent component is also being cached,
// merge self into parent's result
buffer[bufferIndex - 1] += result.html
const prev = componentBuffer[bufferIndex - 1]
result.components.forEach(c => prev.add(c))
}
buffer.length = bufferIndex
componentBuffer.length = bufferIndex
this.next()
break
buffer.length = bufferIndex
componentBuffer.length = bufferIndex
break
}
}
}
}
@@ -1,6 +1,6 @@
/* @flow */

const MAX_STACK_DEPTH = 1000
const MAX_STACK_DEPTH = 900
const noop = _ => _

const defer = typeof process !== 'undefined' && process.nextTick

0 comments on commit e4b1b57

Please sign in to comment.