Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwitchTransition children may be equal if both keys are null #526

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AdrianFleming
Copy link

If the SwitchTransition's children both have a null key then they were not equal. If the Router's location has no key then the children were being continually re-rendered with the animation applied.

Add test for null key
If this was called with a key of the Router's location.key and this is null then the children were not equal and the transition was repeatedly fading in and out. This could be seen by opening a new window and browsing to a site where the user had a valid token.
Fix broken build, {null} not null
Copy link
Member

@taion taion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they have literally no key, then I don't see how we can say one thing or another. In this kind of case, why couldn't you just take e.g. "@@unknown" or something as a fallback key and be more explicit in application space, as opposed to forcing the library into potentially-surprising behavior?

@@ -8,8 +8,7 @@ function areChildrenDifferent(oldChildren, newChildren) {
if (
React.isValidElement(oldChildren) &&
React.isValidElement(newChildren) &&
oldChildren.key != null &&
oldChildren.key === newChildren.key
((oldChildren.key == null && newChildren.key == null) || oldChildren.key === newChildren.key)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we want to treat null and undefined the same here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taion, OK. This is how I initially coded it but decided it would be better handled in the component. I'll close the fork therefore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants