πͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(table-views): shared view links carry applied filters; URL as source of truth (LFE-10486, LFE-7389) (#14521)
Nikita Kabardind23e9a52c0b8
diff --git a/web/src/components/table/data-table-toolbar.tsx b/web/src/components/table/data-table-toolbar.tsxindex 5aa41f1e8e..59b633c5a6 100644--- a/web/src/components/table/data-table-toolbar.tsx+++ b/web/src/components/table/data-table-toolbar.tsx@@ -90,6 +90,7 @@ interface SearchConfig {interface TableViewControllers {applyViewState: (viewData: TableViewPresetState) => void;selectedViewId: string | null;+ appliedViewId: string | null;handleSetViewId: (viewId: string | null) => void;}diff --git a/web/src/components/table/table-view-presets/components/data-table-view-presets-drawer.tsx b/web/src/components/table/table-view-presets/components/data-table-view-presets-drawer.tsxindex b1fe0cf74a..5ecff44ae6 100644--- a/web/src/components/table/table-view-presets/components/data-table-view-presets-drawer.tsx+++ b/web/src/components/table/table-view-presets/components/data-table-view-presets-drawer.tsx@@ -77,6 +77,8 @@ import { useForm } from "react-hook-form";import { zodResolver } from "@hookform/resolvers/zod";import { z } from "zod";import { showErrorToast } from "@/src/features/notifications/showErrorToast";+import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";+import { copyTextToClipboard } from "@/src/utils/clipboard";import { useUniqueNameValidation } from "@/src/hooks/useUniqueNameValidation";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { useHasProjectAccess } from "@/src/features/rbac/utils/checkProjectAccess";@@ -138,6 +140,9 @@ interface TableViewPresetsDrawerProps {projectId: string;controllers: {selectedViewId: string | null;+ /** The view whose full state was actually applied this session (null on a+ * shared-link visit where the view is intentionally not applied). */+ appliedViewId: string | null;handleSetViewId: (viewId: string | null) => void;applyViewState: (viewData: TableViewPresetState) => void;};@@ -176,7 +181,8 @@ export function TableViewPresetsDrawer({}: TableViewPresetsDrawerProps) {const [searchQuery, setSearchQueryLocal] = useState("");const { tableName, projectId, controllers } = viewConfig;- const { handleSetViewId, applyViewState, selectedViewId } = controllers;+ const { handleSetViewId, applyViewState, selectedViewId, appliedViewId } =+ controllers;const { TableViewPresetsList } = useViewData({ tableName, projectId });const {createMutation,@@ -300,6 +306,27 @@ export function TableViewPresetsDrawer({name: updatedView.name,});+ // Column order/visibility are the visitor's per-table localStorage, which+ // only reflects this view when the view was actually applied this session.+ // On a shared-link visit the view is intentionally not applied, so+ // `currentState`'s columns are the visitor's own unrelated layout β sending+ // them would silently overwrite the saved view's columns. In that case keep+ // the view's stored column layout instead (LFE-10486). Filters/sort/search+ // always come from the live state, since updating those to what the visitor+ // currently sees is exactly the intent.+ const viewWasApplied = appliedViewId === selectedViewId;+ const storedView = TableViewPresetsList?.find(+ (view) => view.id === selectedViewId,+ );+ const columnOrder =+ viewWasApplied || !storedView+ ? currentState.columnOrder+ : storedView.columnOrder;+ const columnVisibility =+ viewWasApplied || !storedView+ ? currentState.columnVisibility+ : storedView.columnVisibility;+updateConfigMutation.mutate({projectId,name: updatedView.name,@@ -307,8 +334,8 @@ export function TableViewPresetsDrawer({tableName,orderBy: currentState.orderBy,filters: currentState.filters,- columnOrder: currentState.columnOrder,- columnVisibility: currentState.columnVisibility,+ columnOrder,+ columnVisibility,searchQuery: currentState.searchQuery,});};@@ -356,6 +383,36 @@ export function TableViewPresetsDrawer({viewId,});+ // For the view that is currently active, the page URL already encodes the+ // applied filters, sort and search β the URL is the source of truth. Share+ // it verbatim so in-view edits travel with the link. A server-built+ // `?viewId=β¦` permalink points at the saved view's stored state and would+ // silently drop those edits, which is the recipient-gets-stale-filters bug+ // (LFE-10486). Non-active views still get a clean link to the saved view.+ if (+ viewId === selectedViewId &&+ typeof window !== "undefined" &&+ window.location?.href+ ) {+ // Toast on the clipboard write's resolution: a permission failure must+ // surface an error instead of falsely reporting success.+ copyTextToClipboard(window.location.href)+ .then(() =>+ showSuccessToast({+ title: "Permalink copied to clipboard",+ description: "You can now share the permalink with others",+ }),+ )+ .catch(() =>+ showErrorToast(+ "Failed to copy permalink",+ "Could not write to the clipboard. Please copy the page URL manually.",+ "WARNING",+ ),+ );+ return;+ }+if (window.location.origin) {generatePermalinkMutation.mutate({viewId,diff --git a/web/src/components/table/table-view-presets/hooks/useTableViewManager.ts b/web/src/components/table/table-view-presets/hooks/useTableViewManager.tsindex c321338e97..0b3ba5c138 100644--- a/web/src/components/table/table-view-presets/hooks/useTableViewManager.ts+++ b/web/src/components/table/table-view-presets/hooks/useTableViewManager.ts@@ -97,8 +97,6 @@ export function useTableViewManager({const [isInitialized, setIsInitialized] = useState(false);const [isLoading, setIsLoading] = useState(true);const capture = usePostHogClientCapture();- const pendingFiltersRef = useRef<FilterState | null>(null);- const pendingFiltersPreviousStateRef = useRef<FilterState | null>(null);const [storedViewId, setStoredViewId] = useSessionStorage<string | null>(`${tableName}-${projectId}-viewId`,@@ -174,30 +172,43 @@ export function useTableViewManager({if (isInitialized) return;if (!isRouterReady) return;- // If viewId already in the URL and is not a system preset, let the getById- // query resolve it.+ // Clear stale frontend-only system presets from the URL first (they are+ // defined in code, not the DB, so there is nothing to fetch).if (selectedViewId &&- (!isSystemPresetId(selectedViewId) || allowBackendSystemPresets)+ isSystemPresetId(selectedViewId) &&+ !allowBackendSystemPresets) {- return;- }-- // Clear stale frontend-only system presets from the URL.- if (selectedViewId && isSystemPresetId(selectedViewId)) {handleSetViewId(null);return;}- // Query params such as `filter` are explicit table state. They must take- // precedence over implicit session/default view restoration, otherwise a- // direct filtered URL is immediately overwritten by the restored view.+ const hasResolvableView =+ !!selectedViewId &&+ (!isSystemPresetId(selectedViewId) || allowBackendSystemPresets);++ // Explicit table state in the URL (`filter`/`search`/`searchType`/+ // `orderBy`) is authoritative, even when a `viewId` is present. The viewId+ // is a provenance reference β which saved view a link came from β but the+ // URL's filters/sort/search are what is actually applied (the URL is the+ // source of truth). We do NOT fetch or apply the saved view here: applying+ // it would overwrite the URL's filters, and writing its column layout would+ // silently mutate the visitor's own per-table localStorage on a+ // non-deliberate link open. The viewId stays in the URL so the drawer still+ // shows the originating view. Preserves deep-link precedence (#13865) and+ // makes shared links carry in-view edits (LFE-10486).if (hasExplicitTableStateInUrl(router.query)) {setIsInitialized(true);setIsLoading(false);return;}+ // A real saved view (or an allowed backend system preset) in the URL with+ // no explicit table state β let the getById query resolve and hydrate it.+ if (hasResolvableView) {+ return;+ }+// Priority 1: Session storage (from a previous visit to this table)if (storedViewId &&@@ -299,16 +310,11 @@ export function useTableViewManager({setExpandedFiltersRef.current(nextExpandedFilters);}- if (setFiltersRef.current) {+ // Apply the view's filters unless what is applied already matches. The+ // sidebar filter hook updates optimistically, so the applied filter state+ // β and the URL it writes to β reflect the view synchronously.+ if (setFiltersRef.current && !filtersAlreadyApplied) {setFiltersRef.current(validFilters);- // Track expected filters to observe when state actually updates (for useEffect below)- // If filters are already applied, don't set pending ref (will unlock immediately).- // Also track pre-apply state so we can unlock when filters propagate but get- // migrated into an equivalent shape by downstream hooks.- if (!filtersAlreadyApplied) {- pendingFiltersRef.current = validFilters;- pendingFiltersPreviousStateRef.current = currentFilterState ?? [];- }}if (setSearchQueryRef.current) {@@ -333,14 +339,15 @@ export function useTableViewManager({if (viewData.columnVisibility)setColumnVisibility(viewData.columnVisibility);- // If filters were already applied, unlock table immediately- if (filtersAlreadyApplied) {- setIsLoading(false);- }-- // NOTE: Table remains locked until useEffect observer detects filter state propagation- // This is relevant for the saved views. Because the URL lazy updates and we don't want to wait- // for a page reload+ // Unlock as soon as the view is applied. Earlier versions kept the table+ // locked until a useEffect observer saw the filter change propagate to+ // `currentFilterState`; that observer was the source of LFE-7389+ // fragility β an early return or a canonicalized-shape mismatch could+ // leave the table showing unfiltered rows, or never unlock. The sidebar+ // filter hook applies updates optimistically, so propagation is+ // synchronous and the URL becomes the source of truth for the applied+ // filters on the same render. Unlock deterministically here instead.+ setIsLoading(false);},[setColumnOrder,@@ -365,6 +372,10 @@ export function useTableViewManager({isRouterReady &&!!selectedViewId &&!isInitialized &&+ // Explicit URL state is authoritative and we deliberately do not apply+ // the view over it (no filter overwrite, no localStorage column+ // mutation on a link open) β so there is nothing to fetch.+ !hasExplicitTableStateInUrl(router.query) &&(!isSystemPresetId(selectedViewId) || allowBackendSystemPresets),},);@@ -375,6 +386,15 @@ export function useTableViewManager({const requestedViewId = selectedViewId;if (!requestedViewId) return;if (isInitializedRef.current) return;+ // Explicit URL state is authoritative and the view is deliberately not+ // applied over it β guard here too (not just via the query `enabled`) so+ // cached view data can never apply the view on the first render regardless+ // of effect timing (LFE-10486).+ if (hasExplicitTableStateInUrl(router.query)) {+ setIsInitialized(true);+ setIsLoading(false);+ return;+ }if (selectedViewIdRef.current !== requestedViewId) return;if (selectedViewData.id !== requestedViewId) return;if (!isViewApplicableToTable(tableName, selectedViewData.tableName)) {@@ -400,6 +420,7 @@ export function useTableViewManager({isSelectedViewSuccess,selectedViewData,selectedViewId,+ router.query,handleSetViewId,capture,tableName,@@ -429,35 +450,13 @@ export function useTableViewManager({handleSetViewId,]);- // Observe when filter state propagates from saved view- // After calling setFilters, URL updates async β filterState recalculates β this effect detects completion- useEffect(() => {- const pendingFilters = pendingFiltersRef.current;- if (!pendingFilters || currentFilterState === undefined) return;-- const preApplyFilters = pendingFiltersPreviousStateRef.current ?? [];- const hasExpectedShape = isEqual(currentFilterState, pendingFilters);- const hasPropagatedWithCanonicalization = !isEqual(- currentFilterState,- preApplyFilters,- );-- if (hasExpectedShape || hasPropagatedWithCanonicalization) {- // Filter state has synchronized - safe to unlock table.- // `hasPropagatedWithCanonicalization` handles equivalent rewrites- // (for example legacy env-delta -> canonical none-of shape).- pendingFiltersRef.current = null;- pendingFiltersPreviousStateRef.current = null;- setIsLoading(false);- }- }, [currentFilterState]);-if (disabled) {return {isLoading: false,applyViewState: () => {},handleSetViewId: () => {},selectedViewId: null,+ appliedViewId: null,defaultViewScope: null,};}@@ -467,6 +466,32 @@ export function useTableViewManager({applyViewState,handleSetViewId,selectedViewId,+ // The view whose state is reflected in the live table β i.e. whose column+ // layout is in localStorage. We reuse `storedViewId` (session-persisted,+ // set on apply/create/select and cleared on deselect) rather than a+ // session-scoped React flag, so the signal survives a reload: after a view+ // is applied the URL becomes `?viewId=X&filter=...`, and on reload the+ // explicit-URL-state short-circuit skips re-applying it β but storedViewId+ // is still X, so "Update view" correctly trusts the live columns instead of+ // reverting to the view's stored snapshot. On a fresh shared-link visit+ // storedViewId is null (or another view), so the view's columns are+ // preserved (the visitor's own localStorage layout is not saved over the+ // view).+ //+ // Deliberate tradeoff: storedViewId is sessionStorage (per-tab) while the+ // column layout is localStorage (cross-tab). So the *owner* reopening their+ // own `?viewId=X&filter=...` bookmark in a NEW tab is indistinguishable at+ // runtime from a stranger opening a shared link β both have empty+ // sessionStorage + explicit URL state. We intentionally err toward+ // preserving the saved view's stored columns when ambiguous: the cost is+ // that an in-tab column reorder in that new tab is not saved on "Update+ // view" (recoverable β re-select the view, then update), whereas trusting+ // the live columns would let any visitor silently overwrite a shared view's+ // columns. A robust resolution needs the column-state-model rework+ // (decouple "the view's columns" from "my personal columns"); a per-tab+ // signal cannot tell the two visits apart. Keep this comment if "fixing"+ // the symmetric case is attempted. (LFE-10486)+ appliedViewId: storedViewId,defaultViewScope: resolvedDefault?.scope ?? null,};}diff --git a/web/src/components/table/table-view-presets/hooks/useViewMutations.ts b/web/src/components/table/table-view-presets/hooks/useViewMutations.tsindex e3a292d1b2..6006c4cec6 100644--- a/web/src/components/table/table-view-presets/hooks/useViewMutations.ts+++ b/web/src/components/table/table-view-presets/hooks/useViewMutations.ts@@ -1,4 +1,5 @@import { showSuccessToast } from "@/src/features/notifications/showSuccessToast";+import { showErrorToast } from "@/src/features/notifications/showErrorToast";import { api } from "@/src/utils/api";import { copyTextToClipboard } from "@/src/utils/clipboard";@@ -47,11 +48,22 @@ export const useViewMutations = ({const generatePermalinkMutation =api.TableViewPresets.generatePermalink.useMutation({onSuccess: (data) => {- copyTextToClipboard(data);- showSuccessToast({- title: "Permalink copied to clipboard",- description: "You can now share the permalink with others",- });+ // Toast on the clipboard write's resolution so a permission failure+ // surfaces an error instead of falsely reporting success.+ copyTextToClipboard(data)+ .then(() =>+ showSuccessToast({+ title: "Permalink copied to clipboard",+ description: "You can now share the permalink with others",+ }),+ )+ .catch(() =>+ showErrorToast(+ "Failed to copy permalink",+ "Could not write to the clipboard. Please copy the link manually.",+ "WARNING",+ ),+ );},});diff --git a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsxindex dde4bc89b6..26891da895 100644--- a/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx+++ b/web/src/features/filters/savedViewImplicitEnvironmentRegression.clienttest.tsx@@ -174,7 +174,13 @@ const TEST_OPTIONS = {name: ["checkout", "search"],};-function SavedViewHarness() {+function SavedViewHarness({+ setColumnOrder = () => {},+ setColumnVisibility = () => {},+}: {+ setColumnOrder?: (columnOrder: string[]) => void;+ setColumnVisibility?: (columnVisibility: Record<string, boolean>) => void;+} = {}) {const queryFilter = useSidebarFilterState(TEST_FILTER_CONFIG, TEST_OPTIONS, {stateLocation: "urlAndSessionStorage",sessionFilterContextId: null,@@ -183,13 +189,13 @@ function SavedViewHarness() {},});- const { isLoading } = useTableViewManager({+ const { isLoading, appliedViewId } = useTableViewManager({tableName: TableViewPresetTableName.Traces,projectId: "project-1",stateUpdaters: {setFilters: queryFilter.setFilterState,- setColumnOrder: () => {},- setColumnVisibility: () => {},+ setColumnOrder,+ setColumnVisibility,},validationContext: {columns: [],@@ -203,6 +209,7 @@ function SavedViewHarness() {return (<div><div data-testid="loading-state">{isLoading ? "loading" : "ready"}</div>+ <div data-testid="applied-view-id">{appliedViewId ?? "null"}</div><pre data-testid="explicit-state">{JSON.stringify(queryFilter.explicitFilterState)}</pre>@@ -346,6 +353,109 @@ describe("Saved view restore with implicit environment defaults", () => {);});+ it("applies explicit URL filters over the saved view when both viewId and filter are present (LFE-10486)", async () => {+ // A shared "saved view + in-view filter edits" link carries both the+ // viewId (provenance) and an explicit, edited filter. The edited filter+ // must win; the saved view's stored filter must not overwrite it.+ const explicitUrlFilters: FilterState = [+ {+ column: "name",+ type: "stringOptions",+ operator: "any of",+ value: ["search"],+ },+ ];+ const encodedFilters = encodeFiltersGeneric(explicitUrlFilters);++ queryParamStore.set("viewId", "view-1");+ queryParamStore.set("filter", encodedFilters);+ mockUseRouter.mockReturnValue({+ isReady: true,+ query: { viewId: "view-1", filter: encodedFilters },+ });++ // The view also carries a column layout. It must NOT be applied here:+ // column order/visibility are the visitor's own per-table localStorage, and+ // opening a shared link is not a deliberate action β applying the view's+ // columns would silently overwrite the visitor's saved layout.+ const setColumnOrder = vi.fn();+ const setColumnVisibility = vi.fn();+ mockGetByIdUseQuery.mockReturnValue({+ data: {+ id: "view-1",+ name: "View with columns",+ tableName: TableViewPresetTableName.Traces,+ projectId: "project-1",+ orderBy: null,+ filters: OLD_SAVED_VIEW_FILTERS,+ columnOrder: ["name", "latency"],+ columnVisibility: { input: false },+ searchQuery: "",+ createdAt: new Date("2026-01-01T00:00:00.000Z"),+ updatedAt: new Date("2026-01-01T00:00:00.000Z"),+ createdBy: "user-1",+ createdByUser: null,+ },+ error: null,+ });++ render(+ <SavedViewHarness+ setColumnOrder={setColumnOrder}+ setColumnVisibility={setColumnVisibility}+ />,+ );++ await waitFor(() => {+ expect(screen.getByTestId("loading-state").textContent).toBe("ready");+ });++ // The URL's filter ("search") wins over the saved view's stored filter+ // ("checkout" from OLD_SAVED_VIEW_FILTERS).+ expect(screen.getByTestId("explicit-state").textContent).toContain(+ "search",+ );+ expect(screen.getByTestId("explicit-state").textContent).not.toContain(+ "checkout",+ );+ // The viewId stays in the URL as a provenance reference so the drawer can+ // still show the view the link came from.+ expect(queryParamStore.get("viewId")).toBe("view-1");+ // The view is not applied over explicit URL state, so the visitor's own+ // column layout is left untouched (no localStorage mutation on link open).+ expect(setColumnOrder).not.toHaveBeenCalled();+ expect(setColumnVisibility).not.toHaveBeenCalled();+ // On a fresh shared-link visit the view is NOT recognised as applied, so+ // "Update view" would preserve the view's stored columns (not the+ // visitor's). Contrast with the reload-of-applied-view test below.+ expect(screen.getByTestId("applied-view-id").textContent).toBe("null");+ });++ it("recognises a reload of an applied view as applied so Update keeps live columns (LFE-10486)", async () => {+ // Reload after a view was applied: the URL carries the viewId AND the+ // view's hydrated filters, and the session still remembers X as active.+ // The explicit-URL-state short-circuit means the view is not re-applied,+ // but it must still be recognised as the applied view β otherwise a+ // column reorder + "Update view" would silently discard the reorder and+ // save the stored snapshot instead.+ const hydratedFilters = encodeFiltersGeneric(OLD_SAVED_VIEW_FILTERS);+ queryParamStore.set("viewId", "view-1");+ queryParamStore.set("filter", hydratedFilters);+ mockUseRouter.mockReturnValue({+ isReady: true,+ query: { viewId: "view-1", filter: hydratedFilters },+ });+ sessionStorage.setItem("traces-project-1-viewId", JSON.stringify("view-1"));++ render(<SavedViewHarness />);++ await waitFor(() => {+ expect(screen.getByTestId("loading-state").textContent).toBe("ready");+ });++ expect(screen.getByTestId("applied-view-id").textContent).toBe("view-1");+ });+it("does not apply a default saved view over explicit URL filters", async () => {const explicitUrlFilters: FilterState = [{