Skip to content

Commit 6c7d144

Browse files
fix(tables): clear state when the active view is deleted externally
1 parent da8a17a commit 6c7d144

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

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

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ export function Table({
394394
* `undefined` means "nothing seeded yet" so the first resolve still runs. */
395395
const seededViewIdRef = useRef<string | null | undefined>(undefined)
396396

397+
/**
398+
* A view this client just created, held only until the list refetch carries it.
399+
* Distinct from `seededViewIdRef`, which is stamped on EVERY selection — reusing
400+
* that for the create race also matched a view that had been selected normally
401+
* and then deleted, so the delete never cleaned up.
402+
*/
403+
const pendingCreatedViewIdRef = useRef<string | null>(null)
404+
397405
/**
398406
* Applies a view's config to the live state. `keep` marks slices the user has
399407
* already set by hand, which win over the view's stored values on the FIRST
@@ -464,14 +472,18 @@ export function Table({
464472
return
465473
}
466474

467-
// A selected id that doesn't resolve is one of two things. Ours — "Save as
468-
// view" stamps `seededViewIdRef` before writing the URL, so the id can name a
469-
// view the list hasn't refetched yet; clearing there would wipe the filter
470-
// just saved. Or genuinely dead (deleted by someone else, stale bookmark), in
471-
// which case leaving it applied would keep the grid narrowed under an "All"
475+
// The id resolved, so any create race for it is over.
476+
if (activeView && pendingCreatedViewIdRef.current === activeView.id) {
477+
pendingCreatedViewIdRef.current = null
478+
}
479+
480+
// A selected id that doesn't resolve is one of two things. Ours — creation
481+
// writes the URL before the list refetches, and clearing there would wipe the
482+
// config just saved. Or genuinely dead (deleted by someone else, stale
483+
// bookmark), where leaving it applied keeps the grid narrowed under an "All"
472484
// label, since the menu resolves the same missing view to null.
473485
if (activeViewId !== null && activeViewId !== ALL_VIEW_PARAM && !activeView) {
474-
if (seededViewIdRef.current === activeViewId) return
486+
if (pendingCreatedViewIdRef.current === activeViewId) return
475487
seededViewIdRef.current = null
476488
setTableParams({ view: ALL_VIEW_PARAM })
477489
applyViewConfig(null)
@@ -640,6 +652,7 @@ export function Table({
640652
// Stamp before selecting so the resolve effect treats this as already
641653
// seeded — it can't tell a just-created view from a dead id otherwise.
642654
seededViewIdRef.current = view.id
655+
pendingCreatedViewIdRef.current = view.id
643656
setTableParams({ view: view.id })
644657
// Which means the blank config must be applied here; nuqs batches this
645658
// sort write with the `view` write above into one URL update.

0 commit comments

Comments
 (0)