-
Notifications
You must be signed in to change notification settings - Fork 639
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
Browser: tab transitions, state update queue #5582
Conversation
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.
The video you posted confirmed this is indeed the best way we can approach this from so I support it. Once it's in we can look into what patterns of the existing codebase could fit, and even if they do we need to confirm it doesn't degrade perf.
Aside from that my main question is: Why do we need a queue? Opening many tabs too fast? or closing tabs to fast?
If that's the case, for simplicity purposes, avoiding bugs / race conditions, I think we could simplify this by disabling the buttons (new tab / close tab) for ~ 1 second after interacting with them. While I do think this is really cool seems like overkill for the basic open / close tabs scenarios.
If the reason we have the queue is different, then might be acceptable to keep it.
Bruno and I chatted and decided the queue makes sense given the speed at which tab closing can happen. I think at least one of the sync bugs was caused by code I’d already commented out, haven’t been able to break it so going to mark this as ready for review and we can move on from this but keep an eye out for issues (very well may exist but should be easily addressable once found). We can circle back to making further improvements later if needed. Will catch this up with develop in a bit and add in some error logging to catch any failed operations or mismatches between |
Same logic but less confusing
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.
🔥 🔥 🔥
* Browser: tab transitions, state update queue (#5582) * Tab transitions, add tab state update queue * Move unblocking to the end of setTabStatesThenUnblockQueue, remove some commented code * Remove commented code, adjust newTab checks * Make condition more readable Same logic but less confusing * Fix background color conversion * Remove redundant multipleTabsOpen logic, make conditions more legible * Fade in tabs on mount, clean up WebViewBorder * Fix part of the scroll jank * Queue logic cleanup, add some error logging TODOs * Catch up with develop * Remove unnecessary runOnJS * More performant fade in on mount * Lower fade duration * Lint --------- Co-authored-by: Christian Baroni <7061887+christianbaroni@users.noreply.github.com> * Catch up close button fixes with develop Also includes a few additional fixes * Merge remote-tracking branch 'origin/@bruno/fix-close-tab-btn' into @christian/fix-close-tab-btn --------- Co-authored-by: Christian Baroni <7061887+christianbaroni@users.noreply.github.com>
…e-changes * 'develop' of github.com:rainbow-me/rainbow: (44 commits) allow open in new tab (#5610) added warning for unknown price impact (#5597) fix cloudflare protection (#5609) improve type checking on web preferences (#5607) fix scrolltoindex firing on last card dismissal (#5606) make account network switcher work (#5604) Dapp browser fixes (#5596) Fix close tab btn (#5598) browser: add account context menu (#5603) Fix instant screenshot setting (#5602) swaps: bump sdk (#5583) Browser: tab transitions, state update queue (#5582) audit: undici (#5594) [SWAPS V2]: Add token search logic and ability to select assets (#5547) swaps v2 gas (#5526) tx sim: other natives (#5585) Brody/bump 1.9.21 3 (#5588) fix sheet bg (#5590) Only hold the active tab ref in BrowserContext (#5579) Dapp browser: disable tab closing for empty state (#5573) ...
* 'develop' of github.com:rainbow-me/rainbow: make account network switcher work (#5604) Dapp browser fixes (#5596) Fix close tab btn (#5598) browser: add account context menu (#5603) Fix instant screenshot setting (#5602) swaps: bump sdk (#5583) Browser: tab transitions, state update queue (#5582) audit: undici (#5594) [SWAPS V2]: Add token search logic and ability to select assets (#5547) swaps v2 gas (#5526) tx sim: other natives (#5585) Brody/bump 1.9.21 3 (#5588) fix sheet bg (#5590)
What changed (plus any additional context for devs)
This PR adds tab transitions when closing or opening tabs and introduces a reanimated-based orchestration layer between the browser UI and the tabStates data, which allows for updates to tabStates to apply successfully and in the correct order the majority of the time, and I think with a bit more work it could be every time. Currently it's scoped to state updates related to closing and opening tabs. Here's what this orchestration layer is doing:
currentlyOpenTabIds
, which is updated at the exact moment a tab creation or close operation is initiated. This shared value is only ever read and set from worklets, and the positions of the IDs in the array correspond to the tab indexes.I also converted closeTab and newTab to worklets, which were already being called in most cases from reanimated/gesture handler worklets
There are a couple bugs still but it works pretty well. I think currentlyOpenTabIds can become out of sync with tabStates if for some reason an operation fails to complete (maybe possible), or operations apply in a different order in currentlyOpenTabIds vs tabStates (resulting in mismatched tab indexes). There’s no cleanup in place in the event that does happen. If we end up going with this approach it’d be easy to add a cleanup condition and some logging to the useAnimatedReaction that coordinates the operation queue, and we can fix the remaining issues.
I think a lot of this could move out of the BrowserContext or into hooks, I left it there for simplicity and wanted to get a yay/nay on the idea first — am fine to walk away from this if there’s a better alternative, I was just having fun with it over the weekend
The logic is a little messy/redundant/complex in places but doesn’t seem to have much negative performance impact if any, and tab closing/opening is seemingly reliable no matter how fast you do it (unless you manage to trigger one of the sync bugs I mentioned, in which case a force quit will resolve it)
Screen recordings / screenshots
RPReplay_Final1712042348.mov