Skip to content

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

[EMB-2567] Fix stale custom viz settings after the SDK allowlist changes (#85363)

Nicolò Pretto0fcbea607d5b
diff --git a/enterprise/frontend/src/embedding-sdk-ee/custom-viz/initialize.ts b/enterprise/frontend/src/embedding-sdk-ee/custom-viz/initialize.ts
index 2c385c11c8f..cb546dad8d2 100644
--- a/enterprise/frontend/src/embedding-sdk-ee/custom-viz/initialize.ts
+++ b/enterprise/frontend/src/embedding-sdk-ee/custom-viz/initialize.ts
@@ -13,10 +13,12 @@ import {
PLUGIN_CUSTOM_VIZ,
} from "metabase/plugins";
import type { DispatchFn } from "metabase/redux/hooks";
+import { useForceUpdate } from "metabase/utils/use-force-update";
import {
getCustomPluginIdentifier,
getPluginAssetUrl,
} from "metabase/visualizations/custom-visualizations/custom-viz-utils";
+import { visualizations } from "metabase/viz-core";
import { hasPremiumFeature } from "metabase-enterprise/settings";
import type {
CustomVizPluginId,
@@ -195,16 +197,29 @@ export function initializeSdkCustomVizPlugin() {
// Regular (non-custom) displays are always allowed.
!isCustomVizDisplay(display) || isCustomVizAllowed(display, allowlist);
+ // A plugin could have been loaded under a previous allow list and needs
+ // to be removed. We keep the viz unmounted (reporting loading) until it's
+ // unregistered, so it remounts with the fallback settings.
+ const needsUnregister =
+ isCustomVizDisplay(display) && !allowed && visualizations.has(display);
+ const forceUpdate = useForceUpdate();
+
useEffect(() => {
- if (isCustomVizDisplay(display) && !allowed) {
+ if (needsUnregister && isCustomVizDisplay(display)) {
unregisterCustomVizDisplay(display);
+ forceUpdate();
}
- }, [display, allowed]);
+ }, [display, needsUnregister, forceUpdate]);
- return eeUseAutoLoadCustomVizPlugin(allowed ? display : undefined, {
- sandboxMode,
- onMessage: logUnavailableCustomVizMessage,
- });
+ const result = eeUseAutoLoadCustomVizPlugin(
+ allowed ? display : undefined,
+ {
+ sandboxMode,
+ onMessage: logUnavailableCustomVizMessage,
+ },
+ );
+
+ return { ...result, loading: result.loading || needsUnregister };
},
useCustomVizPlugins: (opts?: { enabled?: boolean }) => {