-
Notifications
You must be signed in to change notification settings - Fork 46.4k
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
Update scroll restoration logic in suspense fixture #13437
Update scroll restoration logic in suspense fixture #13437
Conversation
Let's see. It seems to me that we should scroll to top when going:
But not when going:
Do you agree with that? Let me know if not. |
@sophiebits Extra points for doing proper scroll restoration, such as:
|
@sophiebits Yep those conditions sound correct to me. I initially thought that the second and third bullet points in the cases where we should restore scroll wouldn't be possible states. However, if the UI changes for example the "Return to List" button becoming sticky at the top of the window, or next and previous buttons to navigate between team members get added then we would want to still support those cases. With those in mind it seems like the logic should be something like
if (
prevState.showDetail !== this.state.showDetail ||
(prevState.currentId !== this.state.currentId && this.state.showDetail)
) {
// restore scroll
} Let me know if this updated snippet seems to cover those cases correctly. @plievone I think your solution would work really well, however it feels a bit like over-engineering a solution in my opinion. I find it really nice to see these fixtures as simple as they are at the moment to help developers understand the core concept of what they are showcasing. On top of testing the feature they have the added benefit of teaching new developers how to implement the feature as well. Happy to discuss more about it though! |
@hamlim That sounds good to me! |
…ist or changing from detail page to another detail page
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Thanks!
Awesome, thanks again for the issue, and the feedback! |
This change should fix the issue raised in #13436.
The extra check of ensuring that
showDetail
has changed (i.e.prevState.showDetail !== this.state.showDetail
) might not be necessary, however I wanted to make sure we don't callscrollTo
too frequently.Before submitting a pull request, please make sure the following is done:
master
.yarn
in the repository root.yarn test
). Tip:yarn test --watch TestName
is helpful in development.yarn test-prod
to test in the production environment. It supports the same options asyarn test
.yarn debug-test --watch TestName
, openchrome://inspect
, and press "Inspect".yarn prettier
).yarn lint
). Tip:yarn linc
to only check changed files.yarn flow
).Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html