chadek opened a new pull request, #44470:
URL: https://github.com/apache/superset/pull/44470

   ### SUMMARY
   Fixes #44468.
   
   The iframe's load listener fires on every load, reloads included, and opens 
a fresh MessageChannel each time — but it only returns that channel through 
resolve() of a promise that is already settled from the second load onwards. 
Nobody keeps the new port1, so a dashboard that navigates itself (tab link, 
link in a Markdown chart, drill-down) leaves a blank frame: the new document 
waits for a guest token on a channel whose other end is gone, while ourPort 
keeps talking to the document that disappeared. 
[#39860](https://github.com/apache/superset/pull/39860) already made the 
embedded page tolerate a second 'port transfer' handshake; this completes the 
host half.
   
   connect(iframe) is extracted from the listener: it opens the channel, 
transfers the port, constructs and starts the Switchboard, and replays the 
host-defined methods — a reloaded document has never heard of them.
   ourPort, refreshTimer and unmounted move above mountIframe, which now 
resolves void; the listener reassigns ourPort on every load. The existing 
accessors (getScrollSize, getActiveTabs, setDataMask, …) read that variable, so 
they follow the current port with no change.
   A reload cancels the pending timer and re-fetches a token rather than 
replaying the cached one: refresh happens 5s before expiry, so a reload landing 
just before it would hand the new page a token with seconds to live and its GET 
/api/v1/me/roles/ would 401 into the "session interrupted" banner.
   refreshGuestToken takes a generation number and bails out if a reload 
superseded it, so a refresh left in flight cannot emit a stale token or arm a 
second timer.
   resolvePermalinkUrl and observeDataMask are registered through 
defineHostMethod so they survive a reload.
   A load arriving after unmount() is now ignored — on master it still opens a 
channel. Covered by a test.
   MessagePort queues what arrives before start(), so emitting the token right 
after the handshake is safe; that is already the property the first load relies 
on.
   
   No API change, no change to the host's token endpoint, to the Superset 
instance, or to how the iframe is mounted.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — no UI change in Superset itself. Before: clicking a link internal to 
an embedded dashboard leaves an empty frame until the host remounts the iframe. 
After: the target page renders with its data.
   
   ### TESTING INSTRUCTIONS
   Unit: cd superset-embedded-sdk && npm test — three new tests in 
src/index.test.ts cover re-authentication on the new port, the replay of 
host-defined methods, and a load arriving after unmount(). All three fail on 
master and pass here; the 17 existing tests are unaffected.
   
   Manual: embed a dashboard containing a link internal to the dashboard, click 
it, and check that the target page renders and that the network tab shows one 
call to the host's guest-token endpoint per reload, followed by the page's 
chart/data calls. Leave the page open longer than the guest token's lifetime 
and navigate again: the refresh follows the current port.
   
   ### ADDITIONAL INFORMATION
   [x] Has associated issue: #44468
   [ ] Required feature flags:
   [ ] Changes UI
   [ ] Includes DB Migration
   [ ] Introduces new feature or API
   [ ] Removes existing feature or API


-- 
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