Skip to content

Commit 85f0440

Browse files
committed
🤖 fix: always enable stats tab in storybook
Change-Id: I662fb8e367d427e04fc7cb8705f23710dcc39d8f Signed-off-by: Thomas Kosiewski <[email protected]>
1 parent 7c43b8c commit 85f0440

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/browser/contexts/FeatureFlagsContext.tsx

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
11
import React, { createContext, useContext, useEffect, useState, type ReactNode } from "react";
22
import { useAPI } from "@/browser/contexts/API";
33

4-
function isStorybookIframe(): boolean {
5-
return typeof window !== "undefined" && window.location.pathname.endsWith("iframe.html");
4+
function isStorybook(): boolean {
5+
if (typeof window === "undefined") {
6+
return false;
7+
}
8+
9+
// Storybook preview iframe is usually /iframe.html, but test-runner debug URLs
10+
// (and sometimes the manager itself) use ?path=/story/... .
11+
if (window.location.pathname.endsWith("iframe.html")) {
12+
return true;
13+
}
14+
15+
const params = new URLSearchParams(window.location.search);
16+
const path = params.get("path");
17+
if (path && path.startsWith("/story/")) {
18+
return true;
19+
}
20+
21+
// Some configurations pass story identity via ?id=...
22+
if (params.has("id")) {
23+
return true;
24+
}
25+
26+
return false;
627
}
728

829
export type StatsTabVariant = "control" | "stats";
@@ -31,7 +52,7 @@ export function useFeatureFlags(): FeatureFlagsContextValue {
3152
export function FeatureFlagsProvider(props: { children: ReactNode }) {
3253
const { api } = useAPI();
3354
const [statsTabState, setStatsTabState] = useState<StatsTabState | null>(() => {
34-
if (isStorybookIframe()) {
55+
if (isStorybook()) {
3556
return { enabled: true, variant: "stats", override: "default" };
3657
}
3758

@@ -58,7 +79,7 @@ export function FeatureFlagsProvider(props: { children: ReactNode }) {
5879
};
5980

6081
useEffect(() => {
61-
if (isStorybookIframe()) {
82+
if (isStorybook()) {
6283
return;
6384
}
6485

0 commit comments

Comments
 (0)