sheet-router icon indicating copy to clipboard operation
sheet-router copied to clipboard

[question] scroll position

Open nichoth opened this issue 7 years ago • 5 comments

When we use the back and forward buttons we expect the scroll position to be where we left off at. How do you handle scroll position? Does this library provide a mechanism for it?

nichoth avatar Aug 23 '16 18:08 nichoth

@nichoth nope so far this lib only does routing and all stuff related with that. E.g. instrument the history API, handle links to trigger the router, etc.

I'm not sure what the story is about scroll position. I haven't given it much though, but figured virtual doms would handle this. Could you perhaps provide some more information on this? How does persisting scroll position work, and what's the use case? Should we handle it?

yoshuawuyts avatar Aug 25 '16 11:08 yoshuawuyts

I've always used single-page which passes you the previous scroll position when the route changes, but it is a lower level module. I would like to better encapsulate this functionality, not sure how though. Here is an example of it in use, where we jump to that position after rendering the new view. https://github.com/nichoth/tiny-thunder/blob/master/src/lib/routes/index.js#L19

nichoth avatar Aug 25 '16 17:08 nichoth

@nichoth would it be viable to save scrollposition on a per-view basis? perhaps with a lil history listener + subscription or something?

yoshuawuyts avatar Aug 29 '16 15:08 yoshuawuyts

It makes sense for scroll position to be part of UI state like everything else. We need a hook somewhere during page changes that gets the scroll position when someone leaves a view. Then the view needs to go to the scroll position iff the user got there via the back button. So the minimum that we need to know from the router is if the route was triggered via back button or click. Maybe we don't want to save scroll state in the router. I will eventually do more work on this, because I have to figure it out for my project.

nichoth avatar Aug 29 '16 19:08 nichoth

It makes sense for scroll position to be part of UI state like everything else

Yeah I think that's fair. Though scrollstate can also a thing on a per-component basis, but I feel like that might be a bit more of an edge case. What do you think the right API for this would be?

yoshuawuyts avatar Sep 03 '16 16:09 yoshuawuyts