Skip to content

The Open Standard for Generative UI

fix(react-ui): remount artifact list on category switch (#898)

abhithesyse0f2d12de122
diff --git a/packages/react-ui/src/components/AgentInterface/AgentInterface.tsx b/packages/react-ui/src/components/AgentInterface/AgentInterface.tsx
index 99dab597a..cb90cd7b9 100644
--- a/packages/react-ui/src/components/AgentInterface/AgentInterface.tsx
+++ b/packages/react-ui/src/components/AgentInterface/AgentInterface.tsx
@@ -417,7 +417,13 @@ const AgentInterfaceBody = ({
<MobileHeader />
))}
{artifactPath.kind === "list" ? (
- <ArtifactBrowserPage categoryName={artifactPath.categoryName} />
+ // Keyed on category so switching categories remounts with fresh
+ // state instead of rendering the previous category's list while the
+ // new one loads.
+ <ArtifactBrowserPage
+ key={artifactPath.categoryName ?? "__all__"}
+ categoryName={artifactPath.categoryName}
+ />
) : (
<ArtifactViewPage
artifactId={artifactPath.artifactId}
diff --git a/packages/react-ui/src/components/AgentInterface/ArtifactBrowserPage.tsx b/packages/react-ui/src/components/AgentInterface/ArtifactBrowserPage.tsx
index d5ed60bb2..a3c82259a 100644
--- a/packages/react-ui/src/components/AgentInterface/ArtifactBrowserPage.tsx
+++ b/packages/react-ui/src/components/AgentInterface/ArtifactBrowserPage.tsx
@@ -114,7 +114,10 @@ export const ArtifactBrowserPage = ({ categoryName }: { categoryName?: string })
const [debouncedSearch, setDebouncedSearch] = useState("");
const [artifacts, setArtifacts] = useState<ArtifactSummary[]>([]);
const [nextCursor, setNextCursor] = useState<string | undefined>(undefined);
- const [isLoading, setIsLoading] = useState(false);
+ // Starts true so a fresh mount (see the `key` on this component at its render
+ // site — the category name) shows the loader immediately rather than flashing
+ // the empty state before the fetch effect runs.
+ const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState<Error | null>(null);
const requestIdRef = useRef(0);