Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): wait for dashboard route params before project-scoped queries (#17163)

cursor[bot]7a0368efa4cc
diff --git a/web/src/features/dashboard/DashboardDetailPage.tsx b/web/src/features/dashboard/DashboardDetailPage.tsx
index 6d54de014e..ea310de1cb 100644
--- a/web/src/features/dashboard/DashboardDetailPage.tsx
+++ b/web/src/features/dashboard/DashboardDetailPage.tsx
@@ -88,6 +88,10 @@ import { extractTransferFiles } from "@/src/components/editor/fileDropPaste";
import { Layer } from "@/src/components/ui/layer";
import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";
import { useDashboardDefinitionDraft } from "@/src/features/dashboard/hooks/useDashboardDefinitionDraft";
+import {
+ RouteParamsPendingFallback,
+ useReadyRouteParams,
+} from "@/src/hooks/useReadyRouteParams";
// Position for a tile inserted "next to" an anchor tile: same size,
// immediately to the right when that fits the 12-column grid, otherwise
@@ -106,9 +110,12 @@ function placementNextTo(anchor: DashboardPlacement) {
// read path — an unresolved session used to read as v3 and fire a wave of
// legacy-table queries that was thrown away once the session landed.
export default function DashboardDetailPage() {
- const router = useRouter();
- const { projectId } = router.query as { projectId: string };
+ const route = useReadyRouteParams(["projectId", "dashboardId"]);
const { readPath } = useReadPath();
+ if (!route.ready) {
+ return <RouteParamsPendingFallback />;
+ }
+ const { projectId } = route.params;
if (readPath === "unknown") {
return (
<Page
diff --git a/web/src/utils/api.clienttest.ts b/web/src/utils/api.clienttest.ts
index c251dc3068..27e6d79b5e 100644
--- a/web/src/utils/api.clienttest.ts
+++ b/web/src/utils/api.clienttest.ts
@@ -576,15 +576,19 @@ describe("isExpectedTrpcClientError", () => {
});
it("does not treat a non-Zod BAD_REQUEST as validation", () => {
- expect(
- isTrpcZodValidationError(
- trpcServerError({
- code: "BAD_REQUEST",
- httpStatus: 400,
- message: "Invalid input, projectId is required",
- }),
- ),
- ).toBe(false);
+ // Protected-project middleware throws this when `projectId` is missing.
+ // That is a client call-site bug (queries firing before pages-router
+ // params hydrate), not expected user input — keep capturing until the
+ // remaining unguarded pages gate on useReadyRouteParams.
+ const error = trpcServerError({
+ code: "BAD_REQUEST",
+ httpStatus: 400,
+ path: "datasets.runsByDatasetId",
+ message: "Invalid input, projectId is required",
+ });
+
+ expect(isTrpcZodValidationError(error)).toBe(false);
+ expect(isExpectedTrpcClientError(error)).toBe(false);
});
it("does not suppress an unrecognized tRPC code", () => {