Repository navigation
fix(web): preserve board scroll position when closing or editing tasks - #855
Conversation
Updating `?taskId=` via `window.history.pushState({}, ...)` triggered
TanStack History's patched history listener and stripped `__TSR_key`
from `history.state`. With router `scrollRestoration: true`, closing a
task modal caused TanStack Router to fall back to keying by bare
`location.href` and restore any stale cached scroll entry (such as
top-left `0, 0`) onto the board scroll container.
In addition, once a view/filter scope had loaded, introducing a new
column query (e.g. editing a task's tag, assignee, or custom field value,
or loading more sprint columns) flipped `tasksLoading` back to `true`
and unmounted `BoardView` behind the open modal, resetting scroll to
top-left on remount.
- Replace raw `window.history.pushState({}, ...)` with
`syncTaskIdSearchParam`, which uses `replaceState` while preserving
`window.history.state` and setting `router.history._ignoreSubscribers`
so updating `?taskId=` does not trigger a route load or scroll
restoration.
- Keep the mounted board/list alive in `areColumnQueriesLoading` when
additional columns start fetching after the current view/filter scope
has already loaded.
- Add regression tests covering both scroll-restoration preservation
with TanStack Router and incremental column loading.
Fixes Paca-AI#642
There was a problem hiding this comment.
✅ No new issues found.
Approach: sound — the modal's ?taskId= sync is kept out of TanStack Router's load and scroll-restoration path, and the board is kept mounted when incremental columns fetch.
Reviewed changes
- Silent
?taskId=sync —syncTaskIdSearchParamreplaces the localpushState({}, ...)helpers, preservinghistory.state(__TSR_key/__TSR_index) and settinghistory._ignoreSubscribersso no route load or scroll restore fires. Verified_ignoreSubscribersis a realRouterHistoryfield in the locked@tanstack/[email protected], anduseRouter({ warn: false })is valid in@tanstack/[email protected]. - Board no longer unmounts for incremental columns —
tasksLoadingnow routes throughareColumnQueriesLoadingwith a latched loaded scope key; a task edit introducing a new tag/assignee/custom-field column keeps<BoardView>/<ListView>mounted, while first loads of a view/filter scope and full cache loss still show the skeleton. - Regression coverage — added
interaction-scroll.test.tsx(real router withscrollRestoration: true, asserting no router load and noscrollToon open/close) and fourareColumnQueriesLoadingunit cases.
Validated locally: tsc -b and biome clean on the changed files; the full src/components/projects/interactions suite (228 tests) passes.
Verified the root causes against the locked library sources: router-core keys its scroll cache by location.state.__TSR_key || location.href, so preserving state removes the stale-href snap; colBaseOpts/colBaseOptsKey are filter-derived, so new columns from a task edit do not change colScopeKey and correctly avoid the skeleton.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
Fixes #642, where scrolling right on a multi-column board, opening a task modal (optionally editing it), and closing the modal snapped the board scroll position back to the top-left.
Root Causes
window.history.pushState({}, ...):InteractionLayoutupdated?taskId=usingwindow.history.pushState({}, "", url.toString()).@tanstack/historypatches bothpushStateandreplaceStateto notify the router, and passing{}erased__TSR_keyfromhistory.state. Becauserouter.tsxenablesscrollRestoration: true, TanStack Router fell back to keying by barelocation.href; whenever a stale(0, 0)scroll entry existed inscrollRestorationCachefor that board URL (e.g., from an earlier visit or prior modal close at top-left), closing the modal restored that stale entry and jumped the board back to top-left.columnQueries. BecausetasksLoadingcheckedcolumnQueries.some(q => q.data === undefined && q.fetchStatus !== "idle"),<BoardView>unmounted to<BoardViewSkeleton>behind the open modal and remounted at(0, 0).Changes
apps/web/src/components/projects/interactions/view-utils.ts:syncTaskIdSearchParam(taskId, history)to update?taskId=viawindow.history.replaceStatewhile preservingwindow.history.stateand togglingrouter.history._ignoreSubscribers, avoiding unwanted route loads and scroll restoration.areColumnQueriesLoading(columnQueries, hasLoadedCurrentScope)so initial view/filter loads still wait for all columns before rendering the board, while incremental columns added after the scope has loaded keep the mounted board intact.apps/web/src/components/projects/interactions/interaction-layout.tsx:useRouter({ warn: false })intosyncTaskIdSearchParamfor opening, closing, and 404-clearing?taskId=.activeViewId|columnBy|colBaseOptsKey) and routedtasksLoadingthroughareColumnQueriesLoading.apps/web/src/components/projects/interactions/interaction-scroll.test.tsxreproducing the exact TanStack RouterscrollRestoration: truetop-left snap and asserting scroll preservation across modal open/close.areColumnQueriesLoadinginapps/web/src/components/projects/interactions/view-utils.test.ts.Type of Change
Checklist