Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix embedModalEnableEmbedding race with pending React remount (#74815)

Sébastien900e1abd5aee
diff --git a/e2e/support/helpers/e2e-embedding-iframe-sdk-setup-helpers.ts b/e2e/support/helpers/e2e-embedding-iframe-sdk-setup-helpers.ts
index 32e37270364..cc22dc1e8f6 100644
--- a/e2e/support/helpers/e2e-embedding-iframe-sdk-setup-helpers.ts
+++ b/e2e/support/helpers/e2e-embedding-iframe-sdk-setup-helpers.ts
@@ -6,24 +6,26 @@ export const embedModalEnableEmbeddingCard = () =>
export const embedModalEnableEmbedding = () => {
cy.get("body").then(($body) => {
- const $card = $body.find('[data-testid="enable-embedding-card"]');
-
- // No enable card on screen — terms were already accepted before mount.
- if ($card.length === 0) {
- return;
- }
-
- // Once accepted, the action button becomes disabled and shows "Enabled".
- // The card itself stays mounted, so guard against double-clicks.
- if ($card.find("button:disabled").length > 0) {
+ // No card mounted — terms were accepted in the test setup, the section
+ // bails early via `showSection` (see EnableModularEmbeddingSection /
+ // EnableGuestEmbedsSection) and never renders.
+ if ($body.find('[data-testid="enable-embedding-card"]').length === 0) {
return;
}
- embedModalEnableEmbeddingCard().within(() => {
- cy.findByText(
- /(Agree and (continue|enable)|Enable and continue)/,
- ).click();
- });
+ // Wait for the actionable Agree/Enable button on the freshly mounted
+ // section for the currently-selected auth mode, then click it.
+ //
+ // We intentionally do NOT treat the disabled "Enabled" label as a
+ // terminal no-op: it appears legitimately after this helper clicks
+ // Agree (the section freezes via `useState`), but it ALSO appears
+ // transiently on the *stale* section from a previous auth-mode
+ // selection before React commits the unmount. Bailing on it was the
+ // original bug. Matching the actionable label scopes us to the new
+ // section automatically, since the stale one shows only "Enabled".
+ cy.findByRole("button", {
+ name: /(Agree and (continue|enable)|Enable and continue)/,
+ }).click();
});
};
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts
index edd18f4dbe7..dc9788058bc 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/helpers/index.ts
@@ -99,12 +99,25 @@ export const navigateToEntitySelectionStep = (
const hasEntitySelection =
experience !== "exploration" && experience !== "metabot";
+ // Switch to the requested auth mode if we're not already on it. When we
+ // ARE already on it (e.g. SSO is the default and `preselectSso` is set),
+ // the radio click is a no-op AND the section's terms were already accepted
+ // by visitNewEmbedPage()'s embedModalEnableEmbedding() — so calling the
+ // helper again would race the now-frozen disabled "Enabled" button.
+ const ensureAuthMode = (label: string) => {
+ cy.findByLabelText(label).then(($radio) => {
+ if ($radio.is(":checked")) {
+ return;
+ }
+ cy.wrap($radio).click();
+ embedModalEnableEmbedding();
+ });
+ };
+
if (preselectSso || !isQuestionOrDashboardExperience) {
- cy.findByLabelText("Metabase account (SSO)").click();
- embedModalEnableEmbedding();
+ ensureAuthMode("Metabase account (SSO)");
} else if (preselectGuest) {
- cy.findByLabelText("Guest").click();
- embedModalEnableEmbedding();
+ ensureAuthMode("Guest");
}
const labelByExperience = match(experience)
diff --git a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
index acbb97619d9..3a23045d922 100644
--- a/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
+++ b/e2e/test/scenarios/embedding/sdk-iframe-embedding-setup/select-embed-options.cy.spec.ts
@@ -94,6 +94,9 @@ describe(suiteTitle, () => {
cy.intercept("GET", "/api/dashboard/**").as("dashboard");
cy.intercept("POST", "/api/card/*/query").as("cardQuery");
+ cy.intercept("PUT", "/api/setting/sdk-iframe-embed-setup-settings").as(
+ "persistSettings",
+ );
mockEmbedJsToDevServer();
});
@@ -965,7 +968,7 @@ describe(suiteTitle, () => {
H.expectUnstructuredSnowplowEvent({
event: "embed_wizard_options_completed",
event_detail:
- "settings=custom,experience=dashboard,authType=sso,drills=true,withDownloads=false,withSubscriptions=false,withTitle=true,isSaveEnabled=false,theme=custom",
+ "settings=custom,experience=dashboard,authType=sso,drills=true,withDownloads=false,withSubscriptions=false,withTitle=true,theme=custom",
});
// derived-colors-for-embed-flow.unit.spec.ts contains the tests for other derived colors.
@@ -976,6 +979,13 @@ describe(suiteTitle, () => {
// Should no longer derive background-hover as it is color-mix'd
// in the colors configuration
codeBlock().should("not.contain", '"background-hover"');
+
+ // Wait for the debounced theme persist to land before the test ends —
+ // otherwise the orphaned `_.debounce` callback in `useUserSetting` fires
+ // after `H.restore()` of the next test and writes the custom theme back
+ // into the freshly-restored DB, polluting downstream snowplow assertions.
+ // Proper fix (flush-on-unmount in `useUserSetting`) tracked in EMB-1795.
+ cy.wait("@persistSettings");
});
it("can toggle the Metabot layout from auto to stacked to sidebar", () => {
diff --git a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts
index 27f5b755b5b..86055fe14cf 100644
--- a/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts
+++ b/frontend/src/metabase/embedding/embedding-iframe-sdk-setup/utils/get-adjusted-sdk-iframe-embed-setting.ts
@@ -45,9 +45,14 @@ export const getAdjustedSdkIframeEmbedSetting = ({
},
({ settings }) => ({
...settings,
- drills: "drills" in defaultSettings && defaultSettings.drills,
- isSaveEnabled:
- "isSaveEnabled" in defaultSettings && defaultSettings.isSaveEnabled,
+ // Skip when the experience defaults don't define the key — otherwise
+ // we'd stamp a stray `false` onto settings for experiences that don't
+ // support it (e.g. dashboard has no `isSaveEnabled`), which would
+ // leak into Snowplow analytics for those resources.
+ ...("drills" in defaultSettings && { drills: defaultSettings.drills }),
+ ...("isSaveEnabled" in defaultSettings && {
+ isSaveEnabled: defaultSettings.isSaveEnabled,
+ }),
...getCommonEmbedSettings({
experience,
isGuestEmbedsEnabled,