Skip to content

fix(web): preserve board scroll position when closing or editing tasks - #855

Merged
pikann merged 1 commit into
Paca-AI:masterfrom
zooqueen:fix/issue-642-preserve-board-scroll-position
Dec 3, 2026
Merged

pikann merged 1 commit into
Paca-AI:masterfrom
zooqueen:fix/issue-642-preserve-board-scroll-position

Conversation

@zooqueen

@zooqueen zooqueen commented Dec 3, 2026

Copy link
Copy Markdown

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

  1. Router scroll restoration triggered by window.history.pushState({}, ...): InteractionLayout updated ?taskId= using window.history.pushState({}, "", url.toString()). @tanstack/history patches both pushState and replaceState to notify the router, and passing {} erased __TSR_key from history.state. Because router.tsx enables scrollRestoration: true, TanStack Router fell back to keying by bare location.href; whenever a stale (0, 0) scroll entry existed in scrollRestorationCache for 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.
  2. Board unmounting to skeleton when a new column starts fetching: Once a board view had loaded, editing a task in a way that introduced a new column (e.g., a new tag, assignee, reporter, or custom-field value) or loading more sprint columns added a pending query to columnQueries. Because tasksLoading checked columnQueries.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:
    • Added syncTaskIdSearchParam(taskId, history) to update ?taskId= via window.history.replaceState while preserving window.history.state and toggling router.history._ignoreSubscribers, avoiding unwanted route loads and scroll restoration.
    • Added 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:
    • Wired useRouter({ warn: false }) into syncTaskIdSearchParam for opening, closing, and 404-clearing ?taskId=.
    • Tracked the loaded column scope (activeViewId|columnBy|colBaseOptsKey) and routed tasksLoading through areColumnQueriesLoading.
  • Regression tests:
    • Added apps/web/src/components/projects/interactions/interaction-scroll.test.tsx reproducing the exact TanStack Router scrollRestoration: true top-left snap and asserting scroll preservation across modal open/close.
    • Added unit tests for areColumnQueriesLoading in apps/web/src/components/projects/interactions/view-utils.test.ts.

Type of Change

  • Other (Bug fix)

Checklist

  • The change is focused and scoped.
  • Tests are added for the changed behavior.
  • Non-obvious tradeoffs and root causes are explained clearly.
  • Avoided unnecessary detail or premature abstraction.

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — syncTaskIdSearchParam replaces the local pushState({}, ...) helpers, preserving history.state (__TSR_key/__TSR_index) and setting history._ignoreSubscribers so no route load or scroll restore fires. Verified _ignoreSubscribers is a real RouterHistory field in the locked @tanstack/[email protected], and useRouter({ warn: false }) is valid in @tanstack/[email protected].
  • Board no longer unmounts for incremental columns — tasksLoading now routes through areColumnQueriesLoading with 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 with scrollRestoration: true, asserting no router load and no scrollTo on open/close) and four areColumnQueriesLoading unit 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit 0c0b855 into Paca-AI:master Dec 3, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Issue with page position after some actions

2 participants