You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ms...@apache.org on 2026/05/05 14:52:10 UTC
(superset) branch master updated: fix(embedded): prevent duplicate React root on rehandshake (#39860)
This is an automated email from the ASF dual-hosted git repository.
msyavuz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 586de12a05e fix(embedded): prevent duplicate React root on rehandshake (#39860)
586de12a05e is described below
commit 586de12a05e57f53421aa3c34ec55ee433435c23
Author: Mehmet Salih Yavuz <sa...@proton.me>
AuthorDate: Tue May 5 17:52:01 2026 +0300
fix(embedded): prevent duplicate React root on rehandshake (#39860)
---
superset-frontend/src/embedded/index.tsx | 28 ++++++++++++++++++----------
1 file changed, 18 insertions(+), 10 deletions(-)
diff --git a/superset-frontend/src/embedded/index.tsx b/superset-frontend/src/embedded/index.tsx
index 4d72d5815b4..a7437968678 100644
--- a/superset-frontend/src/embedded/index.tsx
+++ b/superset-frontend/src/embedded/index.tsx
@@ -19,7 +19,7 @@
import 'src/public-path';
import { lazy, Suspense } from 'react';
-import { createRoot } from 'react-dom/client';
+import { createRoot, type Root } from 'react-dom/client';
import { BrowserRouter as Router, Route } from 'react-router-dom';
import { Global } from '@emotion/react';
import { t } from '@apache-superset/core/translation';
@@ -150,6 +150,8 @@ if (!window.parent || window.parent === window) {
// }
let displayedUnauthorizedToast = false;
+let root: Root | null = null;
+let started = false;
/**
* If there is a problem with the guest token, we will start getting
@@ -175,6 +177,8 @@ function guestUnauthorizedHandler() {
}
function start() {
+ if (started) return undefined;
+ started = true;
const getMeWithRole = makeApi<void, { result: UserWithPermissionsAndRoles }>({
method: 'GET',
endpoint: '/api/v1/me/roles/',
@@ -189,16 +193,21 @@ function start() {
type: USER_LOADED,
user: result,
});
- createRoot(appMountPoint).render(<EmbeddedApp />);
+ if (!root) {
+ root = createRoot(appMountPoint);
+ }
+ root.render(<EmbeddedApp />);
},
err => {
- // something is most likely wrong with the guest token
+ // something is most likely wrong with the guest token; reset the guard
+ // so a rehandshake with a valid token can retry.
logging.error(err);
showFailureMessage(
t(
'Something went wrong with embedded authentication. Check the dev console for details.',
),
);
+ started = false;
},
);
}
@@ -243,16 +252,11 @@ window.addEventListener('message', function embeddedPageInitializer(event) {
debug: debugMode,
});
- let started = false;
-
Switchboard.defineMethod(
'guestToken',
({ guestToken }: { guestToken: string }) => {
setupGuestClient(guestToken);
- if (!started) {
- start();
- started = true;
- }
+ start();
},
);
@@ -322,7 +326,7 @@ window.addEventListener('message', function embeddedPageInitializer(event) {
}
});
-// Clean up theme controller on page unload
+// Clean up theme controller and unmount React root on page unload
window.addEventListener('beforeunload', () => {
try {
const controller = getThemeController();
@@ -333,6 +337,10 @@ window.addEventListener('beforeunload', () => {
} catch (error) {
logging.warn('Failed to destroy theme controller:', error);
}
+ if (root) {
+ root.unmount();
+ root = null;
+ }
});
log('embed page is ready to receive messages');