richardfogaca commented on code in PR #40292:
URL: https://github.com/apache/superset/pull/40292#discussion_r3274586086


##########
superset/templates/superset/oauth2.html:
##########
@@ -25,13 +25,25 @@
   <body>
     <script nonce="{{ macros.get_nonce() }}">
       const message = { tabId: '{{ tab_id }}' };
+      let broadcasted = false;
       if (typeof BroadcastChannel !== 'undefined') {
-        const channel = new BroadcastChannel('oauth');
-        channel.postMessage(message);
-        channel.close();
+        try {
+          const channel = new BroadcastChannel('oauth');
+          channel.postMessage(message);
+          channel.close();
+          broadcasted = true;
+        } catch (e) {
+          // fall through to the localStorage fallback below
+        }
+      }
+      if (!broadcasted) {

Review 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.:
   
   ```js
   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 is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to