Skip to content

Commit e4b1b57

Browse files
committed
fix(ssr): adjust call stack size defer threshold
fix #8545
1 parent 19c33a7 commit e4b1b57

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

src/server/render-context.js

+45-46
Original file line numberDiff line numberDiff line change
@@ -66,55 +66,54 @@ export class RenderContext {
6666
}
6767

6868
next () {
69-
const lastState = this.renderStates[this.renderStates.length - 1]
70-
if (isUndef(lastState)) {
71-
return this.done()
72-
}
73-
/* eslint-disable no-case-declarations */
74-
switch (lastState.type) {
75-
case 'Element':
76-
case 'Fragment':
77-
const { children, total } = lastState
78-
const rendered = lastState.rendered++
79-
if (rendered < total) {
80-
this.renderNode(children[rendered], false, this)
81-
} else {
69+
// eslint-disable-next-line
70+
while (true) {
71+
const lastState = this.renderStates[this.renderStates.length - 1]
72+
if (isUndef(lastState)) {
73+
return this.done()
74+
}
75+
/* eslint-disable no-case-declarations */
76+
switch (lastState.type) {
77+
case 'Element':
78+
case 'Fragment':
79+
const { children, total } = lastState
80+
const rendered = lastState.rendered++
81+
if (rendered < total) {
82+
return this.renderNode(children[rendered], false, this)
83+
} else {
84+
this.renderStates.pop()
85+
if (lastState.type === 'Element') {
86+
return this.write(lastState.endTag, this.next)
87+
}
88+
}
89+
break
90+
case 'Component':
8291
this.renderStates.pop()
83-
if (lastState.type === 'Element') {
84-
this.write(lastState.endTag, this.next)
92+
this.activeInstance = lastState.prevActive
93+
break
94+
case 'ComponentWithCache':
95+
this.renderStates.pop()
96+
const { buffer, bufferIndex, componentBuffer, key } = lastState
97+
const result = {
98+
html: buffer[bufferIndex],
99+
components: componentBuffer[bufferIndex]
100+
}
101+
this.cache.set(key, result)
102+
if (bufferIndex === 0) {
103+
// this is a top-level cached component,
104+
// exit caching mode.
105+
this.write.caching = false
85106
} else {
86-
this.next()
107+
// parent component is also being cached,
108+
// merge self into parent's result
109+
buffer[bufferIndex - 1] += result.html
110+
const prev = componentBuffer[bufferIndex - 1]
111+
result.components.forEach(c => prev.add(c))
87112
}
88-
}
89-
break
90-
case 'Component':
91-
this.renderStates.pop()
92-
this.activeInstance = lastState.prevActive
93-
this.next()
94-
break
95-
case 'ComponentWithCache':
96-
this.renderStates.pop()
97-
const { buffer, bufferIndex, componentBuffer, key } = lastState
98-
const result = {
99-
html: buffer[bufferIndex],
100-
components: componentBuffer[bufferIndex]
101-
}
102-
this.cache.set(key, result)
103-
if (bufferIndex === 0) {
104-
// this is a top-level cached component,
105-
// exit caching mode.
106-
this.write.caching = false
107-
} else {
108-
// parent component is also being cached,
109-
// merge self into parent's result
110-
buffer[bufferIndex - 1] += result.html
111-
const prev = componentBuffer[bufferIndex - 1]
112-
result.components.forEach(c => prev.add(c))
113-
}
114-
buffer.length = bufferIndex
115-
componentBuffer.length = bufferIndex
116-
this.next()
117-
break
113+
buffer.length = bufferIndex
114+
componentBuffer.length = bufferIndex
115+
break
116+
}
118117
}
119118
}
120119
}

src/server/write.js

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

3-
const MAX_STACK_DEPTH = 1000
3+
const MAX_STACK_DEPTH = 900
44
const noop = _ => _
55

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

0 commit comments

Comments
 (0)