0
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2026-08-08 17:53:55 +08:00
discourse/app/assets
Chris Alberti fe5a003938
UX: Improve post stream scrolling stability and layout control [backport 2026.1] (#38318)
Backport of #37788 to release/2026.1.

---

- Improves scroll position stability when loading posts above the
viewport by using `scrollBy`-based compensation instead of `scrollTo` +
`offsetCalculator`
- Dynamically hides banners, notices, and footer content when the user
is in the middle of a long topic via a new `scrollState` service and
`{{hideScrollableContent}}` helper
- Triggers loading more posts when navigating to boundary posts via
keyboard (`j`/`k` keys)
- Prevents load-more sentinel from re-triggering during scroll
compensation with a `suppressLoadAbove` flag

When new posts are prepended above the viewport, the component captures
the anchor post's position via `getBoundingClientRect()` before DOM
insertion (using a `beforePrepend` callback in `prependMore()`), then
compensates with `window.scrollBy()` after insertion. This keeps the
reading position visually stable.

A `scrollState` service tracks ref-counted hide requests. The
`{{hideScrollableContent}}` class-based helper registers with the
service and automatically cleans up via `registerDestructor`. The
`application.gjs` and `topic.gjs` templates wrap scrollable content in
`{{#unless shouldHideScrollableContentAbove/Below}}` blocks.

The helper invocations live in `topic.gjs` outside the `{{#unless
loadingFilter}}` guard so content stays hidden during timeline jumps
that temporarily unmount `<PostStream>`.

`updateKeyboardSelectedPostNumber` now checks if the selected post is at
a loaded boundary (`firstAvailablePost` / `lastAvailablePost`) and
triggers `loadMoreAbove` / `loadMoreBelow`. Double-loading is prevented
by existing `canPrependMore` / `canAppendMore` guards.

Co-authored-by: Sérgio Saquetim <1108771+megothss@users.noreply.github.com>
2026-03-06 10:06:47 -06:00
..
images
stylesheets UX: Improve post stream scrolling stability and layout control [backport 2026.1] (#38318) 2026-03-06 10:06:47 -06:00