Skip to content

Commit 33f2376

Browse files
committed
break render recursion, fix #882
1 parent b639bc6 commit 33f2376

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/proxy/createClassProxy.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const blackListedClassMembers = [
2727
'componentDidMount',
2828
'componentWillReceiveProps',
2929
'componentWillUnmount',
30+
'hotComponentRender',
3031

3132
'getInitialState',
3233
'getDefaultProps',
@@ -135,10 +136,10 @@ function createClassProxy(InitialComponent, proxyKey, options) {
135136
},
136137
)
137138

138-
function proxiedRender() {
139-
proxiedUpdate.call(this)
139+
function hotComponentRender() {
140+
// repeating subrender call to keep RENDERED_GENERATION up to date
140141
renderOptions.componentWillRender(this)
141-
142+
proxiedUpdate.call(this)
142143
let result
143144

144145
// We need to use hasOwnProperty here, as the cached result is a React node
@@ -155,10 +156,16 @@ function createClassProxy(InitialComponent, proxyKey, options) {
155156
return renderOptions.componentDidRender(result)
156157
}
157158

159+
function proxiedRender() {
160+
renderOptions.componentWillRender(this)
161+
return hotComponentRender.call(this)
162+
}
163+
158164
const defineProxyMethods = (Proxy, Base = {}) => {
159165
defineClassMembers(Proxy, {
160166
...fakeBasePrototype(Base),
161167
render: proxiedRender,
168+
hotComponentRender,
162169
componentDidMount,
163170
componentWillReceiveProps,
164171
componentWillUnmount,

src/reconciler/hotReplacementRender.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,11 @@ const render = component => {
101101
return []
102102
}
103103
if (isReactClass(component)) {
104-
return component.render()
104+
// not calling real render method to prevent call recursion.
105+
// stateless componets does not have hotComponentRender
106+
return component.hotComponentRender
107+
? component.hotComponentRender()
108+
: component.render()
105109
}
106110
if (isArray(component)) {
107111
return component.map(render)

test/proxy/consistency.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ describe('consistency', () => {
278278
'methodA',
279279
'methodB',
280280
'render',
281+
'hotComponentRender',
281282
'componentDidMount',
282283
'componentWillReceiveProps',
283284
'componentWillUnmount',

0 commit comments

Comments
 (0)