Unloading earlier posts in PostStream shifts the content that is on screen (CLS ~1.0 per trim)
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 48/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- javascript, typescript
- 領域
- frontend, performance
調査の方向性
PostStreamState.ts の _loadNext() と loadPage() から始め、次に common/utils/anchorScroll.js を読んで、再描画とスクロール補正を追跡します。80件を超える投稿のディスカッションを使い、412x823 の viewport で再現し、トリミング中の layout-shift エントリを確認します。スクロール時に目に見えるジャンプが発生せず、大きなシフトも記録されなくなり、以前の投稿の読み込みが保持された範囲と引き続き整合していれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Current Behavior
When you scroll deep into a discussion, PostStreamState#_loadNext() unloads the posts two pages back:
const twoPagesAway = start - PostStreamState.loadCount * 2;
if (twoPagesAway > this.visibleStart && twoPagesAway >= 0) {
this.visibleStart = twoPagesAway + PostStreamState.loadCount + 1;
...
}
loadPage() wraps the resulting redraw in anchorScroll(), and the anchor element and arithmetic are correct — scrollY really does move by the height of the removed posts. But anchorScroll measures, runs m.redraw.sync(), and then sets scrollTop:
https://github.com/flarum/framework/blob/2.x/framework/core/js/src/common/utils/anchorScroll.js
The correction therefore lands after the redraw's layout, so the browser still records the movement. The result is a layout shift of ~1.0 every two pages of scrolling, attributed to the post items that are on screen at the time — plus a jump that visibly costs the reader their place.
Captured at the moment of a trim (mobile viewport 412x823):
range 0-60 -> 41-80, DOM items 60 -> 39, scrollY 17160 -> 6090
v=1.0
DIV.PostStream-item[i=55] prev y=0 h=0 -> cur y=0 h=400
DIV.PostStream-item[i=56] prev y=0 h=0 -> cur y=400 h=228
DIV.PostStream-item[i=57] prev y=0 h=0 -> cur y=628 h=195
Reading one 85-post thread end to end accumulates CLS 1.018. A 752-post thread accumulates ~18, one shift per trim. Desktop is much less affected (~0.003 on the same thread) because the moved area is a smaller fraction of a large viewport.
Steps to Reproduce
- Open a discussion with 80+ posts on a phone-sized viewport (412x823), throttled (~1.6 Mbps, 150 ms latency).
- Scroll down continuously past the third page of posts, until
visibleStartmoves forward. - Observe the jump, and a
layout-shiftentry of ~1.0 whose sources are the on-screenPostStream-items.
Measured with a buffered PerformanceObserver on layout-shift (hadRecentInput excluded), scrolling with real wheel input via CDP Input.dispatchMouseEvent, headless Chrome 140, 4x CPU throttle. Reproduced identically on two rc.8 installs.
Expected Behavior
Trimming the stream should not move what the reader is looking at.
Options, in the order I'd rank them:
-
Keep the space instead of the nodes — when posts are trimmed from the top, carry their measured height as padding on
.PostStreamand release it whenloadPreviousrestores them. Nothing below moves, no scroll manipulation is needed, and the DOM stays bounded.Worth flagging: I tried this as a small patch and it does not work that way. Adding the padding on trim without symmetric handling in
loadPreviousmakes the stream thrash — the scroll position stops matching the loaded range,loadPreviousfires, posts are re-added while the padding stays, and it compounds (on a 752-post thread the padding ran away to 250,000 px andvisibleStartoscillated 21→42→44→46→68→49…). Doing it properly means making "space above" a single consistent notion handled in both directions. -
Correct the scroll without an intermediate layout — adjust the scroll position in the same layout pass as the removal rather than reading offsets around a sync redraw.
-
Trim less often — widen the retention window, ideally viewport-aware. Reduces the frequency but does not remove the shift.
I'm running option 3 as an extension override in production (keep loaded posts, hand back to core above 200) which takes the 85-post thread from 1.018 to 0.018, but that is a mitigation and not the fix.
Environment
- Flarum version: 2.0.0-rc.8
- Website URL: https://pianoclack.com
- Webserver: nginx
- Hosting environment: VPS
- PHP version: 8.4.24
- Browser: Chrome 140 (mobile emulation, and reproduced on real Android Chrome field data)
- 主要言語
- PHP
- スター
- 6.8k
- フォーク
- 891
- 平均マージ
- 1日 10時間
- マージ済み PR(30日)
- 209
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
flarum/framework のほかの issue
-
type/accessibility type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Default language is ignored for anyone who chose a language, when the language selector is hidden対応中かも @1AbdullahButt が 15 日前に担当しました。 オープンtype/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
[2.x] False CLI/Web PHP mismatch when /usr/bin/php differs from the site's FPM対応中かも @lazerg が 15 日前に担当しました。 オープンtype/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
[2.x] A filter on a resource without a searcher returns a 500対応中かも @imorland が今日担当しました。 オープンtype/bug
flarum/framework#5578 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
flarum/framework の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 87/100
Sylius/Sylius#19359 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Add php 8.6オープン
難易度 1/5 1時間未満 初心者へのやさしさ 66/100
mailersend/mailersend-php#199 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Configuration new tool
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
novalo-dev/Prestashop-MCP-Server#366 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 10 日以内に返信