-
Notifications
You must be signed in to change notification settings - Fork 73
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
#15321: Only one tab writes to the DB #382
#15321: Only one tab writes to the DB #382
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
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.
Left comments. However, in general, great job!
@koko57 if you have questions or need clarification on any of my suggestions just let me know 🙂 |
@roryabraham Sorry, I had to take care of my other issues, but I'll address the rest of the comments soon |
@koko57 thanks for pushing this forward. Please ping me when it's ready for review |
@roryabraham I think it's ready for re-review. On separate channels I commented here #382 (comment) - do we really need it? For the unsubscribe logic - as we no longer need to subscribe so many times, I also think it's unnecessary: #382 (comment). Let me know what do you think about it 🙂 |
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 still think we need to add some unsubscribe logic. Even if there are fewer subscriptions, we're never cleaning them up which means we're propagating data to tabs that no longer exist unnecessarily.
@roryabraham I checked it once again and if I understand this logic correctly, after closing tabs we no longer propagate the data to them. Let me know what do you think about it and correct me if I'm wrong with the logic 🙂 |
@@ -0,0 +1,99 @@ | |||
/** | |||
* When you have many tabs in one browser, the data of Onyx is shared between all of them. Since we persist write requests in Onyx, we need to ensure that |
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.
Just realizing that this comment is a bit out-of-date. This code no longer has anything to do with processing write requests.
Let's follow up ASAP with a PR to upgrade Onyx in E/App |
@roryabraham While trying to bump Onyx version in Expensify App I got this error I've opened a draft PR for this - let me know if we can fix it this way |
@roryabraham wdyt? |
Approved #434 |
This PR caused a regression after the Onyx bump. Fixing PR created here: #455 |
Details
This is the 1st part solution to fix the problem of the linked issue. The links to the broader discussion are below. This PR is big because it contains a RN app that contains an example for the e2e tests.
The goal of this PR is to change Onyx execution so that when there are several tabs open, only one of them can write to the DB. This is done by defining a leader tab, and all other tabs defer their writes to this one leader.
Changes included in this PR:
ActiveClientManager
to react-native-onyx and usedBroadcastAPI
instead of the indexedDB to reach a consensus between tabs about who is the leader (the last tab to be open). It uses timestamps in the messages to check that the last tab to send the message is the leader. If for a change the timestamps are the same, the client ID of the tab is used as a tiebreaker.The GH comment with the explanation: Expensify/App#15321 (comment)
The doc with the discussion: https://docs.google.com/document/d/1Psr4Q4A2uH2b7l9CKBuB_dBT-15V4lJ7SOaH4uQOve4/edit
Related Issues
GH_LINK: Expensify/App#15321
Automated Tests
Added e2e tests using playwright. To run them:
npm install
(should install onyx dependencies and the e2e app as well)npm run e2e
ornpm run e2e-ui
to run the e2e testsCurrent result:
Linked PRs
This will require future changes in newDot, since
ActiveClientManager
is now available in react-native-onyx.