Skip to content

Commit de75910

Browse files
authored
fix: preview in deployments (codse#284)
1 parent fd5c0ea commit de75910

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

components/component-preview.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useTheme } from "next-themes";
55

66
import { CopyButton } from "@/components/copy-button";
77
import { Icons } from "@/components/icons";
8+
import { config } from "@/config";
89
import { cn } from "@/lib/utils";
910

1011
interface ComponentPreviewProps extends React.HTMLAttributes<HTMLDivElement> {
@@ -66,6 +67,12 @@ export function ComponentPreview({ name, className, ...props }: ComponentPreview
6667
};
6768
}, []);
6869

70+
let previewBaseUrl = process.env.NEXT_PUBLIC_STORYBOOK_URL;
71+
if (!previewBaseUrl) {
72+
// Fallback to local storybook if env var is not set (useful in action deployment)
73+
previewBaseUrl = config.isProduction ? "/preview" : "http://localhost:6006";
74+
}
75+
6976
return (
7077
<div className={cn("group relative", className)} {...props}>
7178
<div
@@ -83,7 +90,7 @@ export function ComponentPreview({ name, className, ...props }: ComponentPreview
8390
}
8491
>
8592
<iframe
86-
src={`${process.env.NEXT_PUBLIC_STORYBOOK_URL}/iframe.html?globals=backgrounds.grid:!false;theme:${resolvedTheme ?? (typeof localStorage !== "undefined" ? localStorage?.getItem?.("theme") : "")};backgrounds.value:!transparent&viewMode=docs&id=${name}&site:docs=true`}
93+
src={`${previewBaseUrl}/iframe.html?globals=backgrounds.grid:!false;theme:${resolvedTheme ?? (typeof localStorage !== "undefined" ? localStorage?.getItem?.("theme") : "")};backgrounds.value:!transparent&viewMode=docs&id=${name}&site:docs=true`}
8794
className="w-full"
8895
style={{
8996
height: `${Math.max(100, minHeight)}px`,

0 commit comments

Comments
 (0)