The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
fix(sdk): scope SDK-themed Mantine CSS variables to .mb-wrapper to prevent leakage to :root (#72962)
Timofey Kachalovdd6c1e01cba8
diff --git a/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx b/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsxindex 6fb3ade9c17..0ad28fc8701 100644--- a/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx+++ b/e2e/test-component/scenarios/embedding-sdk/styles-tests.cy.spec.tsx@@ -640,6 +640,49 @@ describe("scenarios > embedding-sdk > styles", () => {expectElementToHaveNoAppliedCssRules(tag);}});++ it("SDK-themed Mantine CSS variables should be scoped to .mb-wrapper and not leak to :root", () => {+ const SDK_BRAND_HEX = "#bada55";++ cy.mount(+ <MetabaseProvider+ authConfig={DEFAULT_SDK_AUTH_PROVIDER_CONFIG}+ theme={defineMetabaseTheme({ colors: { brand: SDK_BRAND_HEX } })}+ >+ <StaticQuestion questionId={ORDERS_QUESTION_ID} />+ </MetabaseProvider>,+ );++ getSdkRoot().findByText("Product ID").should("exist");++ const MANTINE_VAR = "--mantine-color-brand-0";++ cy.get(".mb-wrapper")+ .first()+ .then(($wrapper) => {+ const wrapperValue = getComputedStyle($wrapper[0])+ .getPropertyValue(MANTINE_VAR)+ .trim()+ .toLowerCase();++ expect(+ wrapperValue,+ `${MANTINE_VAR} must be set on .mb-wrapper from SDK theme`,+ ).to.not.equal("");++ cy.document().then((doc) => {+ const rootValue = getComputedStyle(doc.documentElement)+ .getPropertyValue(MANTINE_VAR)+ .trim()+ .toLowerCase();++ expect(+ rootValue,+ `SDK-derived ${MANTINE_VAR}=${wrapperValue} must NOT leak to :root (found ${rootValue || "<empty>"})`,+ ).to.not.equal(wrapperValue);+ });+ });+ });});});diff --git a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsxindex cdb422442ed..bfa70ccad1a 100644--- a/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx+++ b/frontend/src/embedding-sdk-bundle/components/private/SdkThemeProvider.tsx@@ -38,7 +38,10 @@ export const SdkThemeProvider = ({ theme, children }: Props) => {withGlobalClasses: withGlobalClasses ?? isInstanceToRender,}}>- <ThemeProvider theme={themeOverride}>+ <ThemeProvider+ theme={themeOverride}+ cssVariablesSelector=".mb-wrapper"+ >{isInstanceToRender && <GlobalSdkCssVariables />}{children}diff --git a/frontend/test/__support__/storybook.tsx b/frontend/test/__support__/storybook.tsxindex 5298d40e199..e78e79902b3 100644--- a/frontend/test/__support__/storybook.tsx+++ b/frontend/test/__support__/storybook.tsx@@ -75,7 +75,7 @@ export const SdkVisualizationWrapper = ({theme?: MetabaseTheme;initialStore?: State;}) => (- <Box fz="0.875rem">+ <Box fz="0.875rem" className="mb-wrapper" data-mantine-color-scheme="light"><VisualizationWrapper initialStore={initialStore}><SdkThemeProvider theme={theme}>{children}</SdkThemeProvider></VisualizationWrapper>@@ -116,8 +116,14 @@ export const SdkVisualizationStory = ({theme,}: IsomorphicVisualizationStoryProps & { theme?: MetabaseTheme }) => {return (- // @ts-expect-error story file- <Box w={1000} h={600} bg={theme?.colors?.background}>+ <Box+ w={1000}+ h={600}+ // @ts-expect-error story file+ bg={theme?.colors?.background}+ className="mb-wrapper"+ data-mantine-color-scheme="light"+ ><VisualizationWrapper><SdkThemeProvider theme={theme}><Visualization rawSeries={rawSeries} width={500} />