Revert "Remove macro/micro tasks during subscriber update"#758
Conversation
Reviewer Checklist
Screenshots/VideosAndroid: HybridAppAndroid: mWeb ChromeiOS: HybridAppiOS: mWeb SafariMacOS: Chrome / Safari |
|
@rafecolton looks like this was merged without a test passing. Please add a note explaining why this was done and remove the |
|
Not an emergency, straight revert. More context in linked thread |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 90f77d8c69
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| }, 0); | ||
| }); | ||
| } | ||
| return Promise.all([nextMacrotaskPromise, Promise.resolve().then(callback)]).then(); |
There was a problem hiding this comment.
Delay scheduled subscriber callbacks past the current tick
prepareSubscriberUpdate() is supposed to move subscriber work to the next macrotask, but Promise.resolve().then(callback) still runs keyChanged()/keysChanged() in the current turn before the setTimeout(0) barrier resolves. That means a connect() that is still hydrating a collection can still be overtaken by an immediate Onyx.set()/merge(), so waitForCollectionCallback subscribers may receive only the just-written member instead of the full collection during startup/reconnect. This is the same race the deleted tests/unit/collectionHydrationTest.ts was covering, so the revert brings back a user-visible initialization regression.
Useful? React with 👍 / 👎.
| cachedCollection[key] = value; | ||
| lastConnectionCallbackData.set(subscriber.subscriptionID, cachedCollection); | ||
| subscriber.callback(cachedCollection, subscriber.key, {[key]: value}); | ||
| continue; |
There was a problem hiding this comment.
Record the last collection snapshot before callback dispatch
This branch used to update lastConnectionCallbackData with the assembled collection before invoking the callback. Without that bookkeeping, waitForCollectionCallback subscribers are no longer deduplicated, so a logically unchanged member can trigger an extra collection callback on the next update. useOnyx opts collection keys into waitForCollectionCallback by default (lib/useOnyx.ts:312), so this becomes a duplicate rerender/repeated side effect for collection hooks; the changed expectation in tests/unit/onyxTest.ts:1555-1558 is already showing the extra callback.
Useful? React with 👍 / 👎.
Details
Reverts #724 so that #754 can be safely merged into App.
More context here
cc @VickyStash @mountiny @fabioh8010 @kubabutkiewicz @Krishna2323
Related Issues
https://expensify.slack.com/archives/C08CZDJFJ77/p1774037642775419?thread_ts=1774036698.125079&cid=C08CZDJFJ77
Automated Tests
N/A, straight revert
Manual Tests
N/A, straight revert
Author Checklist
### Related Issuessection aboveTestssectiontoggleReportand notonIconClick)myBool && <MyComponent />.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)Avataris modified, I verified thatAvataris working as expected in all cases)mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari