You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Fix potential flaw in pure Higher Order Component - #7654
While working on #7557 I realized that the pure higher order component could lead to some potentially unexpected results when used with compose. I decided to document this possible flaw with a unit test and create this pull. I say "possible" because it actually may already be a known thing and it just is my misunderstanding of how pure is intended to function.
Currently pure examines the prototype of the incoming Wrapped component and if the prototype is a class component it extends it so that a shallow compare of state can be used to determine whether a component is re-rendered. Otherwise it only results in a shallow compare of just props.
Now if the expectation is that when pure is used in compose (as the left most function), that the original component does not re-render on shallow compares of state (i.e. MyComp in the test I added), then it's fine as is and there's no bug. However if the expectation is that the original component DOES re-render on shallow compares of state then this is a bug. Also this could just be a usability thing that the developer would have to be aware of when using pure with compose.
I'm only bringing this to your attention in "case" its not something you're already aware of as it could lead to some unexpected wrapped component behaviour if you're not.
How has this been tested?
see unit test demonstrating the potential concern.
@youknowriad I've assigned to you for initial look as I discovered from blame that you primarily implemented this as a part of (#6313). I see the impetus for adding this was for wrapping withSelect and withDispatch HOCs and it appears that the expectation is only "they" are made "pure" (irregardless of what the original component being wrapped by the composed HOCs is). In this case its appears that the expected behaviour for pure is it only wraps and affects its immediate fed component. If so then this pull is invalid and its just something that maybe should be documented as the expectation when using pure as a part of a composed HOC.
Anyways, just thought I'd run this by you (I kinda "hope" its invalid, if so, I can rework the pull to simply update the documentation).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
While working on #7557 I realized that the pure higher order component could lead to some potentially unexpected results when used with
compose. I decided to document this possible flaw with a unit test and create this pull. I say "possible" because it actually may already be a known thing and it just is my misunderstanding of howpureis intended to function.Currently
pureexamines the prototype of the incomingWrappedcomponent and if the prototype is a class component it extends it so that a shallow compare ofstatecan be used to determine whether a component is re-rendered. Otherwise it only results in a shallow compare of just props.Now if the expectation is that when pure is used in compose (as the left most function), that the original component does not re-render on shallow compares of state (i.e.
MyCompin the test I added), then it's fine as is and there's no bug. However if the expectation is that the original component DOES re-render on shallow compares of state then this is a bug. Also this could just be a usability thing that the developer would have to be aware of when using pure with compose.I'm only bringing this to your attention in "case" its not something you're already aware of as it could lead to some unexpected wrapped component behaviour if you're not.
How has this been tested?
Checklist: