-
-
Notifications
You must be signed in to change notification settings - Fork 10.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
[WIP-PoC] [added] useScrollToTopBehavior #2471
Conversation
The idea is trivially that you just use this as another history enhancer, e.g. |
This could be viable as a PR (and not a throwaway) if you also add one for ImitateBrowserBehavior. |
I started with that, but it didn't seem necessary - at least locally, I see browser-style behavior maintained when I go back/forward between history entries. The only missing thing is actually scrolling to top on new history entries. |
I guess we should rename this That said, what do you think of this API of using it as a history enhancer? This is actually not directly relevant for 1.0.0 if we drop it History anyway (beyond cutting the relevant DOM utils out of this repo). |
What about with a hash history? I'm not familiar with that as much as |
Yes, it works with hash history. |
Some problems I recall with that:
That said, I think only scrolling to top like that is a decent approach. I don't think it's possible to fix the issues I mentioned, and I never quite liked the 0.13 implementation from a technical point of view, though based on the lack of complaints it seemed to do well. We should probably consider #2020 though. |
All the more reason to remove #2469 from the 1.0.0 milestone and wait until post-1.0.0 to implement. This isn't a simple fix and requires some nuanced logic. I'd rather not try to fight against that and hold up a bunch of other great features for what is ultimately UX enhancement. |
Let me update this to match the v0.13 implementations so we have a comparison point. I see the glitchiness on Firefox. I still think we can handle this correctly on our side. #2020 will take some additional thought but I don't think our choice of API is going to meaningfully limit us there. The tradeoff really just is that the router feels a little incomplete without scroll management. |
Oh my goodness, I did not read #707 (comment) carefully enough. This is more difficult than I thought. |
@taurose I believe the implementation I just added works for all the cases you've outlined in #707 on both Chrome and Firefox for both browser and hash history. Predictably, it's now significantly more complicated, and I'm correspondingly less convinced that I want to add this - but I believe it does work. |
It doesn't work with async transition hooks though, does it? |
@taurose Oh - I guess we'd need a little more logic there - essentially on e.g. |
I kinda gave up on getting that to work smoothly (ie without any unnecessary scrolls visible to the user) in all browsers I tested back then (Chrome, IE, Firefox). |
Actually, on second thought, maybe you don't do that? In practice an async transition with a remembered scroll position is going to be a |
This is actually the important part. 😉 |
My statement above was wrong, though - restoring scroll position doesn't quite work properly on Firefox when doing a It's not perfect, but would we be comfortable with having merging https://github.com/rackt/react-router/pull/2471/files#diff-ddf5b5adac06d19993f464b68e4034cc or something comparable as a blocker for 1.0.0-final? Another option is the much simpler taion@d7bdd87 which works on Chrome and half-works on Firefox for the "standard" behavior, to the extent that we care more about scrolling to the origin on a new page and less about always restoring the old scroll position. |
@darreng Regarding #2469 (comment), are you using the version from taion@47a6329? Which OS/browser? |
Exactly - taion/react-router@47a6329. OS X 10.10.5, Chrome 46.0.2490.80. Unable to repro in Firefox and Safari. |
Hmm. I'm not seeing that behavior. ~the same setup but I'm on Chrome 48. |
Can you send or share with me somehow, your test-case? |
I just took the animations example in the repo and repeated the content of the |
For Chrome, I suggest running the tests in incognito or a fresh profile. Extensions can tend to mess with things and cause test variability. |
Per @ryanflorence I think the idea will be to leave this in a separate library for the time being until we've stabilized it enough to merge into either React Router or History proper. |
So the conversation has moved elsewhere? Could someone link the new repo here when it is created? |
As promised: https://github.com/rackt/scroll-behavior |
Don't merge this as-is (obviously, since there are no tests or documentation and it's probably not even in the right project).
This is a PoC for #2469 demonstrating a reasonable way to add scroll behavior management without introducing any new concepts.
I was planning on adding another implementation that used an abstract route, but this just seems overall better.
This should really live in rackt/history instead of here, but the relevant (no longer used) DOMUtils functions were in this repo, so it seemed clearer to add it here.