Skip to content

Commit

Permalink
break render recursion, fix #882
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed Mar 8, 2018
1 parent b639bc6 commit 33f2376
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/proxy/createClassProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const blackListedClassMembers = [
'componentDidMount',
'componentWillReceiveProps',
'componentWillUnmount',
'hotComponentRender',

'getInitialState',
'getDefaultProps',
Expand Down Expand Up @@ -135,10 +136,10 @@ function createClassProxy(InitialComponent, proxyKey, options) {
},
)

function proxiedRender() {
proxiedUpdate.call(this)
function hotComponentRender() {
// repeating subrender call to keep RENDERED_GENERATION up to date
renderOptions.componentWillRender(this)

proxiedUpdate.call(this)
let result

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

function proxiedRender() {
renderOptions.componentWillRender(this)
return hotComponentRender.call(this)
}

const defineProxyMethods = (Proxy, Base = {}) => {
defineClassMembers(Proxy, {
...fakeBasePrototype(Base),
render: proxiedRender,
hotComponentRender,
componentDidMount,
componentWillReceiveProps,
componentWillUnmount,
Expand Down
6 changes: 5 additions & 1 deletion src/reconciler/hotReplacementRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ const render = component => {
return []
}
if (isReactClass(component)) {
return component.render()
// not calling real render method to prevent call recursion.
// stateless componets does not have hotComponentRender
return component.hotComponentRender
? component.hotComponentRender()
: component.render()
}
if (isArray(component)) {
return component.map(render)
Expand Down
1 change: 1 addition & 0 deletions test/proxy/consistency.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ describe('consistency', () => {
'methodA',
'methodB',
'render',
'hotComponentRender',
'componentDidMount',
'componentWillReceiveProps',
'componentWillUnmount',
Expand Down

0 comments on commit 33f2376

Please sign in to comment.