-
Notifications
You must be signed in to change notification settings - Fork 121
Enhance view state management by integrating UiStore for scroll position and selected event persistence #160
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
base: main
Are you sure you want to change the base?
Conversation
…ion and selected event persistence addresses httptoolkit/httptoolkit#470 and further adds selected event persistence
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.
Thanks for the contribution @metheos! At a glance it looks like this is very promising, this is a nice improvement I'd definitely like to include. It looks like something has autoformatted all the UI store code along the way though, which makes this impossible to review and would break git blame
later on.
Can you undo that please, so only the actual changes for this PR are included changes?
Should be good now. Missed that when I was testing. Changes were pretty minimal there! |
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.
Thanks @metheos! That's much clearer. I've add a proper review here - I think this will be great, but it needs a little work to tidy up the details and avoid the setTimeout
etc workarounds.
By the way, in case you're not aware, HTTP Toolkit Pro is totally free for all contributors! I've just set up an account linked to your git commit email, just click 'Get Pro' then 'Log into existing account' and enter your email to get started. Thanks for getting involved! 👍
setTimeout(() => { | ||
this.hasRestoredInitialState = true; | ||
}, 100); | ||
}, 100); |
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.
Would be good to avoid the fixed timeouts here. I think we can do so though - we just need to wait until listBodyRef is ready, right? I think we can convert this into a callback ref, which means we can trigger the DOM interaction (updating the scroll position) immediately after that's rendered.
That will be a bit more responsive (no visible jumping around I hope) and should avoid most of the risk of the race condition you're protecting against with hasRestoredInitialState
here as well. Does that make sense?
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.
yes, good idea. I wasn't sure what to look for. I'll get rid of this and set it to be handled by a new callback ref (setListBodyRef)
// If the filtered events changed (e.g., new events loaded), try to restore scroll position | ||
setTimeout(() => { | ||
this.restoreScrollPosition(); | ||
}, 50); |
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.
I'm not sure I totally understand the goal of this bit. Can you explain when this applies in practice, and how it helps? I haven't noticed issues with the scroll position while filtering.
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.
I put it there as more of a safeguard since I've had issues with wonky scroll position behavior depending on the browser/rendering engine in use. We can take it out if you don't expect that to change, I wasn't sure how consistent the web view experience was across platforms.
src/components/view/view-page.tsx
Outdated
// If no URL eventId but we have a persisted selection, restore it | ||
setTimeout(() => { | ||
this.listRef.current?.restoreViewState(); | ||
}, 100); |
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.
Ditto here - we should restructure this to trigger when listRef
is set, directly, instead of guessing how long it'll take.
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.
got it, added new callback (setListRef)
Signed-off-by: Matt Nelson <[email protected]>
I don't think we have a clear case where this is needed - can re-evalate if we find this does have some specific missing edge cases though.
Nice, thanks @metheos! Yes, those were exactly the changes I was looking for. I've taken that a little further, dropped the setTimeout (we don't need to worry much about browser compat - Electron means we effectively ship our own specific browser version for most uses, and I would expect there won't be many issues anyway), and tried to simplify the logic around the view page controlling the list. Can you give it a quick test, and make sure it still works as you expect? I'm not sure if I've missed some case you were trying to cover. If you're happy though, just let me know and I think it's good to merge now. |
Your commit c300f10 removes the intended restoration of the scroll position. Without that code the list will always scroll to the selected event rather than restoring the actual scroll position. |
Hmm, it's just it seems like that was what it was trying to do before though:
But regardless, I think you are right - restoring the scroll position (never jumping to the automatically persisted selected event) by default is the best choice. I should have a minute to look at that and fix up my changes tomorrow, or you're welcome to take a look. Sorry this has been delayed here a while, but we should be able to get it live this week! |
addresses httptoolkit/httptoolkit#470 and further adds selected event persistence