Fix double re-render in LiftWrapper and migrate it to PureComponent#82
Fix double re-render in LiftWrapper and migrate it to PureComponent#82KatSick wants to merge 5 commits intogrammarly:masterfrom
Conversation
|
@KatSick benchmark results look awesome! thanks! @blacktaxi what do you think about those changes? Are we safe to merge it now, or you have any other objections? |
| new RenderMany(this, newProps, n) // eslint-disable-line | ||
| break | ||
| setRenderCache(cache: RenderCache): void { | ||
| if (this.renderCache === cache) { |
There was a problem hiding this comment.
Does it make sense to check equality with !structEq(this.renderCache, cache) as well? Just prevent rendering of the same state twice? This probably should be handled by React itself, but for some reason, we do that in the latest version. https://github.com/grammarly/focal/pull/82/files?diff=split&w=1#diff-71010d1ee0e73a76461ec411a47605c1207b1982317b93bd4fdc7c35fb7c6b1fL403
| } | ||
| // eslint-disable-next-line camelcase | ||
| UNSAFE_componentWillMount() { | ||
| this._subscribe(this.props) |
There was a problem hiding this comment.
Is it possible to move subscribe into constructor to avoid dependency on legacy lifecycle?
In the article Update on async rendering React team provides two examples about pre-fetch and subscription.
When supporting server rendering, it’s currently necessary to provide the data synchronously – componentWillMount was often used for this purpose but the constructor can be used as a replacement.
The Adding event listener suggest to use componentDidMount with initial value - it's not our case. But, they ok with using componentDidUpdate instead of componentWillReceiveProps
@KatSick what do you think?
what was done:
LiftWrapperto PureComponentLiftWrapperlogic to namespaceContext
todo before merge:
renderToStaticMarkupis in unit-tests)Double re-render fix demo:
Screen.Recording.2021-07-26.at.11.19.14.mov