fix(oauth2): idempotent OAuth2 completion and resilient listener#40292
fix(oauth2): idempotent OAuth2 completion and resilient listener#40292betodealmeida wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #40292 +/- ##
=======================================
Coverage 64.13% 64.14%
=======================================
Files 2591 2591
Lines 138367 138373 +6
Branches 32094 32092 -2
=======================================
+ Hits 88746 88754 +8
+ Misses 48091 48089 -2
Partials 1530 1530
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| // fall through to the localStorage fallback below | ||
| } | ||
| } | ||
| if (!broadcasted) { |
There was a problem hiding this comment.
Richard's agent here: the receiver-side handled guard and the BroadcastChannel construction try/catch both make sense to me.
One thing I’d double-check: could we still write the localStorage signal even when BroadcastChannel.postMessage() succeeds? A successful postMessage() only tells us the callback page sent the message; it does not guarantee the original tab had its listener attached at that exact moment. The storage event gives us a second delivery path for that race.
Since the receiver now dedupes with handled, sending both signals should not reintroduce duplicate reruns. I think we can keep the try/catch around both mechanisms, but avoid making storage conditional on broadcasted, e.g.:
try {
const channel = new BroadcastChannel('oauth');
channel.postMessage(message);
channel.close();
} catch (e) {}
try {
localStorage.setItem('oauth2_auth_complete', JSON.stringify(message));
localStorage.removeItem('oauth2_auth_complete');
} catch (e) {}|
This question isn’t related to the pull request. I can only help with questions about the PR’s code or comments. |
SUMMARY
The OAuth2 callback page always emitted both
BroadcastChannelandlocalStoragesignals whenBroadcastChannelwas supported, so a single completion re-triggeredreRunQuery/triggerQuery/onRefreshtwice in the original tab. This PR makes the sender's storage path a true fallback (only whenBroadcastChannelis unavailable or its construction throws), and guard the receiver against duplicate dispatches as a safety net.Additionally, it wraps channel/storage operations in
try/catchso restricted contexts can't abort the flow, and stabilize the listener's effect by reading volatile selector values (chartList,query, etc.) from arefsochartListchanges don't churn the channel and open a race window.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION