Clicking '.more-info' link shifts page scroll position when side info panel expands — scroll should stay anchored to current content #3293
Zak Siddiqui opened 18 hours ago

Motivation

While reading a long page, I often scroll halfway down and then click a .more-info link to expand the side info panel. The panel expansion is useful, but it also moves the content I was reading out of view, which forces me to find my place again every single time. This is disruptive during reviewing/reading and makes the .more-info affordance something I avoid using rather than something I use freely.

Current Behavior

  1. Scroll to roughly the middle of the page.
  2. Click a element of .more-info.
  3. The side info panel expands as expected.
  4. However, the visible portion of the page changes – the scroll position is no longer anchored to the content that was being displayed before the click. The element that was at (or near) the top of the viewport is displaced, so the reader loses their place.

Observed on OneDev 17.2.4.

Expected Behavior

Expanding (or collapsing) the side info panel should not change what the reader is looking at. Whatever content is currently in the viewport before the click should remain in the same position in the viewport afterwards – i.e. the scroll location should stay anchored to the currently displayed content. Only the panel area should reflow.

Proposed Solution

Anchor the scroll position across the layout change caused by the panel expansion:

  1. Try CSS scroll anchoring first. Ensure overflow-anchor is not disabled (overflow-anchor: none) on the containers involved in the reflow, and that the main content area (the scroll container) has overflow-anchor: auto. If the panel and the content live in different scroll containers, or the changed subtree is excluded from anchoring, the browser can't compensate and the viewport jumps — so verify this before writing JS.
  2. If CSS anchoring isn't sufficient, compensate manually in JS. In the click handler for the .more-info link:
    • Before expanding, record the first visible content element and its offset relative to the viewport top (e.g. via getBoundingClientRect()), together with the current scrollTop.
    • Expand the panel.
    • In the same frame/after layout (e.g. requestAnimationFrame), compute the element's new offset and adjust scrollTop by the delta so the element returns to the same viewport position.
    • Apply the same logic on collapse, and guard against no-op cases (delta 0, element no longer in DOM).
  3. Avoid the root cause if possible. If the jump is caused by the panel being inserted above/inside the content flow rather than overlaying it, consider making the panel an overlay/fixed-position element that does not affect document height at all — that removes the need for any scroll compensation.

Investigation Notes (if the above doesn't resolve it)

  • Reproduce on a page that requires vertical scrolling (long issue/PR description) and check whether the browser's scroll anchoring is active on the scroll container (devtools: toggle overflow-anchor and compare behavior).
  • Determine whether the .more-info panel changes document height or whether the content is re-laid out (e.g. width reduction causing text reflow), since width-induced reflow changes the height of content and is a separate class of jump than a pure height change.
  • Check whether the click handler itself causes a scroll (e.g. focus() on the link, scrollIntoView() somewhere in the expand logic, or an anchor href="#" being followed).
1/1
Type
Bug
Priority
Normal
Assignee
Affected Versions
17.2.4
Labels
No labels
Issue Votes (0)
Watchers (2)
Reference
OD-3293
Please wait...
Connection lost or session expired, reload to recover
Page is in error, reload to recover