Skip to content

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

fix(sdk-package,sdk-bundle):Fix inconsistent SDK loader height (#73318)

Mahatthana (Kelvin) Nomsawadib12195839b84
diff --git a/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx b/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx
index f591ffda8a7..0196164d8d7 100644
--- a/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx
+++ b/enterprise/frontend/src/embedding-sdk-package/components/private/ComponentWrapper/ComponentWrapper.tsx
@@ -1,8 +1,10 @@
import {
+ type CSSProperties,
type ComponentProps,
type JSX,
type JSXElementConstructor,
type PropsWithChildren,
+ type ReactNode,
useEffect,
useId,
useMemo,
@@ -43,6 +45,31 @@ type Props<TComponentProps> = {
const NOT_STARTED_LOADING_WAIT_TIMEOUT = 1000;
+// EMB-875: defaults match FlexibleSizeComponent on the bundle side, so the
+// package-side loader/error box matches the post-init box and prevents a
+// position shift when the SDK bundle finishes loading.
+const DEFAULT_BOUNDED_HEIGHT = "600px";
+const DEFAULT_BOUNDED_WIDTH = "100%";
+
+const Box = ({
+ height,
+ width,
+ children,
+}: {
+ height?: CSSProperties["height"];
+ width?: CSSProperties["width"];
+ children: ReactNode;
+}) => (
+ <div
+ style={{
+ height: height ?? DEFAULT_BOUNDED_HEIGHT,
+ width: width ?? DEFAULT_BOUNDED_WIDTH,
+ }}
+ >
+ {children}
+ </div>
+);
+
// When the ComponentWrapper is rendered without being wrapped within the MetabaseProvider,
// the SDK bundle loading is not triggered.
// We wait for 1 second and if the loading state is still not set or Initial - we set the NotStartedLoading error
@@ -155,18 +182,37 @@ const ComponentWrapperInner = <TComponentProps,>({
const { theme } = metabaseProviderProps ?? {};
const adjustedTheme = useMemo(() => applyThemePreset(theme), [theme]);
+ const { height, width } =
+ (componentProps as {
+ height?: CSSProperties["height"];
+ width?: CSSProperties["width"];
+ }) ?? {};
+
if (isError) {
- return <Error theme={adjustedTheme} message={SDK_LOADING_ERROR_MESSAGE} />;
+ return (
+ <Box height={height} width={width}>
+ <Error theme={adjustedTheme} message={SDK_LOADING_ERROR_MESSAGE} />
+ </Box>
+ );
}
if (isNotStartedLoading) {
return (
- <Error theme={adjustedTheme} message={SDK_NOT_STARTED_LOADING_MESSAGE} />
+ <Box height={height} width={width}>
+ <Error
+ theme={adjustedTheme}
+ message={SDK_NOT_STARTED_LOADING_MESSAGE}
+ />
+ </Box>
);
}
if (isLoading || !metabaseProviderInternalProps.loadingState) {
- return <Loader theme={adjustedTheme} />;
+ return (
+ <Box height={height} width={width}>
+ <Loader theme={adjustedTheme} />
+ </Box>
+ );
}
const ComponentProvider = isLoading
diff --git a/enterprise/frontend/src/embedding-sdk-package/components/private/Loader/Loader.tsx b/enterprise/frontend/src/embedding-sdk-package/components/private/Loader/Loader.tsx
index f4327393321..da41bbdb4b1 100644
--- a/enterprise/frontend/src/embedding-sdk-package/components/private/Loader/Loader.tsx
+++ b/enterprise/frontend/src/embedding-sdk-package/components/private/Loader/Loader.tsx
@@ -43,6 +43,7 @@ export const Loader = ({
width: "100%",
height: "100%",
display: "flex",
+ alignItems: "center",
justifyContent: "center",
...style,
}}
diff --git a/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/PublicComponentWrapper.tsx b/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/PublicComponentWrapper.tsx
index 71d738de720..dbb9c604a45 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/PublicComponentWrapper.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/PublicComponentWrapper.tsx
@@ -1,5 +1,9 @@
import { type ReactNode, forwardRef } from "react";
+import {
+ FlexibleSizeComponent,
+ type FlexibleSizeProps,
+} from "embedding-sdk-bundle/components/private/FlexibleSizeComponent";
import { PublicComponentStylesWrapper } from "embedding-sdk-bundle/components/private/PublicComponentStylesWrapper";
import { SdkError } from "embedding-sdk-bundle/components/private/PublicComponentWrapper/SdkError";
import { SdkLoader } from "embedding-sdk-bundle/components/private/PublicComponentWrapper/SdkLoader";
@@ -13,12 +17,16 @@ import type { CommonStylingProps } from "embedding-sdk-bundle/types/props";
export type PublicComponentWrapperProps = {
children: ReactNode;
-} & CommonStylingProps;
+} & CommonStylingProps &
+ Pick<FlexibleSizeProps, "height" | "width">;
export const PublicComponentWrapper = forwardRef<
HTMLDivElement,
PublicComponentWrapperProps
->(function PublicComponentWrapper({ children, className, style }, ref) {
+>(function PublicComponentWrapper(
+ { children, className, style, height, width },
+ ref,
+) {
const initStatus = useSdkSelector(getInitStatus);
const usageProblem = useSdkSelector(getUsageProblem);
const pluginsReady = useArePluginsReady();
@@ -48,9 +56,21 @@ export const PublicComponentWrapper = forwardRef<
content = <SdkLoader />;
}
+ // EMB-875: wrap loader/error early returns in FlexibleSizeComponent so the
+ // box matches the post-init tree's box (which renders its own
+ // FlexibleSizeComponent inside). Prevents loader from collapsing in a
+ // 0-height container then jumping to centered after init.
+ const isEarlyReturn = content !== children;
+
return (
<PublicComponentStylesWrapper className={className} style={style} ref={ref}>
- {content}
+ {isEarlyReturn ? (
+ <FlexibleSizeComponent height={height} width={width}>
+ {content}
+ </FlexibleSizeComponent>
+ ) : (
+ content
+ )}
</PublicComponentStylesWrapper>
);
});
diff --git a/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/withPublicComponentWrapper.tsx b/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/withPublicComponentWrapper.tsx
index a328ce46fb9..dd2cc49adb2 100644
--- a/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/withPublicComponentWrapper.tsx
+++ b/frontend/src/embedding-sdk-bundle/components/private/PublicComponentWrapper/withPublicComponentWrapper.tsx
@@ -1,5 +1,7 @@
import type React from "react";
+import type { FlexibleSizeProps } from "embedding-sdk-bundle/components/private/FlexibleSizeComponent";
+
import { GuestEmbedGuard } from "./GuestEmbedGuard";
import { PublicComponentWrapper } from "./PublicComponentWrapper";
@@ -11,12 +13,13 @@ export function withPublicComponentWrapper<P extends object>(
WrappedComponent.displayName || WrappedComponent.name || "Component";
const WithPublicComponentWrapper: React.FC<P> = (props) => {
+ const { height, width } = props as Partial<FlexibleSizeProps>;
return (
<GuestEmbedGuard
componentName={componentName}
supportsGuestEmbed={supportsGuestEmbed}
>
- <PublicComponentWrapper>
+ <PublicComponentWrapper height={height} width={width}>
<WrappedComponent {...props} />
</PublicComponentWrapper>
</GuestEmbedGuard>