Skip to content

Commit 39c9bc8

Browse files
committed
fix(tables): preserve valid saved sort on stale links
1 parent 03a4e49 commit 39c9bc8

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

  • apps/sim/app/workspace/[workspaceId]/tables/[tableId]

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/table.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -772,17 +772,26 @@ export function Table({
772772
)
773773

774774
/**
775-
* Drops a sort whose column was deleted from both the URL and its persisted
776-
* view. `queryOptions` feeds the query that produces `columns`, so clearing the
777-
* source of truth avoids a dependency cycle and prevents the dead sort from
778-
* returning on reload.
775+
* Drops a sort whose column was deleted from the URL and, only when the saved
776+
* view names that same field, from persistence. A stale deep-link can name a
777+
* missing field while the view still owns a different valid sort, which must
778+
* not be erased.
779779
*/
780780
useEffect(() => {
781781
if (!sortColumn || columns.length === 0) return
782782
if (liveColumnIds.has(sortColumn)) return
783783
setTableParams({ sort: null, dir: null })
784-
persistActiveViewConfig({ sort: null })
785-
}, [sortColumn, columns.length, liveColumnIds, setTableParams, persistActiveViewConfig])
784+
if (activeViewConfig?.sort?.[0]?.field === sortColumn) {
785+
persistActiveViewConfig({ sort: null })
786+
}
787+
}, [
788+
sortColumn,
789+
columns.length,
790+
liveColumnIds,
791+
activeViewConfig?.sort,
792+
setTableParams,
793+
persistActiveViewConfig,
794+
])
786795

787796
/** Column order/width/pinning auto-saves into the active view as the user drags.
788797
* Sent as a `configPatch` so the server merges it — two overlapping layout writes must

0 commit comments

Comments
 (0)