fix(ui-chat): reuse screen preservation for history prepends

This commit is contained in:
imccyu committed 2026-11-06 23:37:22 +08:00
1 parent 0a228f0a6a
commit 33f5c3ba3e
11 files changed
+78 -49

No files matched your search

@@ -21,14 +21,14 @@
en: 993c2985bf6f3c8f
zh: 8f88fb46584fb272
/agent-note-chat-history-consumption-classes-and-interactions/proposal/shared-anchors-and-layout-reads:
en: 2439cd4cb6a81bc4
zh: 63b8c83897a88d2c
en: 3d59702a5b7021ea
zh: 25c9762647c7c0e0
/agent-note-chat-history-consumption-classes-and-interactions/alternatives-considered:
en: 1b9b8eb12ee5dbd7
zh: e4ecc3cdc3375438
en: 7b3b9b0c7b8f293b
zh: e20045fc3080418f
/agent-note-chat-history-consumption-classes-and-interactions/acceptance-criteria:
en: 8a51c549570a5e0d
zh: eb7b3c27b9dcd98c
en: 1b22cf3616302960
zh: 418ead8421a91bee
/agent-note-chat-history-consumption-classes-and-interactions/risks:
en: aee9f541d058818b
zh: 74e4b6098b9f4b46
en: 29e718a7d1c07a68
zh: a81e5bc6c84b0712
@@ -73,7 +73,7 @@ Prefetch reuses the existing 500ms reading sample, scrollend, content commits, a
At `scrollTop ≤ 0.5`, selection uses `beginPaging`'s first paging-anchor rule without a reading-position hit test. `measurePaging()` only captures a `PagingPosition`; `retainPaging()` separately owns persistent preservation and inner-size observation. Stationary preservation and one-shot correction share remount resolution in `resolvePaging()` and inner/outer calculations in `applyPaging()`.
Persistent preservation restores the captured screen position. One-shot correction retains inner and outer scrolling since capture and compensates only layout displacement; it neither enters paging state nor subscribes to inner-size changes, and releases after one application. `finishHistoryPrepend()` returns the actual landing, and commit handling immediately saves it through `reading.preservePosition()` rather than waiting for a later scroll event. The actual conversation scrollport uses `overscroll-behavior-y: none`, without creating smooth scrolling or a new momentum animation.
Persistent preservation and one-shot correction use the same `applyPaging()` formula to restore the captured screen position, compensating the inner scrollport before the outer one. They do not add changes in scrollTop since capture: native anchoring may have caused those changes. Their lifetimes differ: one-shot correction neither enters paging state nor subscribes to inner-size changes, and releases after one application. `finishHistoryPrepend()` returns the actual landing, and commit handling immediately saves it through `reading.preservePosition()` rather than waiting for a later scroll event. The actual conversation scrollport uses `overscroll-behavior-y: none`, without creating smooth scrolling or a new momentum animation.
Distance confirmation still needs current geometry, and one-shot correction after prepend still needs the new position. These reads serve correctness, but placement inside rAF, ResizeObserver, or commit handling alone does not prove they add no layout. Read frequency, read/write ordering, and actual Layout/Paint costs require separate verification; position stability is not performance evidence.
@@ -85,16 +85,18 @@ Distance confirmation still needs current geometry, and one-shot correction afte
**Store separate coordinates and continuously track the first row for one-shot correction.** That duplicates existing paging anchors and can expand scroll ownership; share the position record and calculations while keeping lifetimes separate.
**Add captured-to-current scroll deltas through `preserveMovement`.** The deltas cannot distinguish reader input from native anchoring for the same prepend, so adding them can compensate twice.
## Acceptance criteria
- Default single-stage calls, deferred consumption, and Turn jumps coexist; an old request cannot consume or overwrite a new one.
- Ordinary events do not revive automatic fallback; touch/inner-scroll continuation, manual completion, and unmount cleanup have focused verification.
- One-shot correction does not register persistent observation or undo intervening reader movement; existing persistent and inner preservation do not regress.
- One-shot correction uses the existing screen-restoration formula without persistent observation or duplicate native compensation; persistent and inner preservation do not regress.
- Distance checks use cached viewport height; raw scroll listeners and consumption admission perform no layout reads.
## Risks
**Known issue: `preserveMovement` cannot distinguish native anchoring from reader input.** The shared correction adds changes in the outer and inner scroll positions since capture. A deterministic geometry model confirms duplicate compensation when the browser has already anchored the same prepend: an outer `scrollTop` of `0.5`, or outer `0` with inner `40`, enters the one-shot path and treats the native adjustment as movement to preserve. The resulting additional displacement is an algorithmic limitation, not evidence that every browser exhibits it. Code remains unchanged for this report-only finding; independent actual-browser verification is pending.
Screen restoration uses the measured residual displacement after native anchoring rather than adding scroll-position deltas. It does not preserve arbitrary input movement between capture and application or guarantee an uninterrupted momentum trajectory. Near-zero outer positions, native inner anchoring, and input arriving around the prepend require current-build browser verification.
Explicit navigation and multiple views share a Session, so Chat's automatic waiting policy must not move into the global event source. Manual intent can still wait if usable positioning never becomes available; actual views need cancellation, reconnect, and anchorless-structure verification. One-shot geometry measurement, native inner anchoring, and asynchronous content growth need browser evidence from the current build.
@@ -73,7 +73,7 @@ Session.consumeOlder
顶部 `scrollTop ≤ 0.5` 使用 `beginPaging` 的首条分页锚点规则,不先执行阅读位置命中检测。`measurePaging()` 只采集 `PagingPosition`;`retainPaging()` 单独拥有持续保位和内层尺寸观察。普通静止保位与一次补偿共用 `resolvePaging()` 的重挂载查找及 `applyPaging()` 的内外层计算。
持续保位恢复采集时的屏幕位置。一次补偿保留采集后发生的内外层滚动,只抵消布局位移;它不进入 paging 状态、不注册内层尺寸观察,应用一次后释放。`finishHistoryPrepend()` 返回实际落点,提交处理立即通过 `reading.preservePosition()` 保存阅读位置,不依赖后续 scroll 事件。会话实际滚动容器设置 `overscroll-behavior-y: none`,不创建平滑滚动或新的惯性动画。
持续保位和一次补偿用相同的 `applyPaging()` 公式恢复采集时的屏幕位置,先补内层、再补外层。计算不叠加采集后 scrollTop 的变化,因为这些变化可能已经来自原生锚定。两者只区分生命周期:一次补偿不进入 paging 状态、不注册内层尺寸观察,应用一次后释放。`finishHistoryPrepend()` 返回实际落点,提交处理立即通过 `reading.preservePosition()` 保存阅读位置,不依赖后续 scroll 事件。会话实际滚动容器设置 `overscroll-behavior-y: none`,不创建平滑滚动或新的惯性动画。
距离检查仍需要当前几何;前插后的一次补偿仍需要读取新位置。这些读数有正确性用途,但不能仅凭位于 rAF、ResizeObserver 或提交回调中,就认定不会增加布局。读取频率、读写顺序及实际 Layout/Paint 成本分别验收;位置不漂移不能替代性能证明。
@@ -85,16 +85,18 @@ Session.consumeOlder
**为一次补偿另存坐标并持续追踪首行。** 与既有分页锚点重复,并可能扩大滚动控制;共享位置记录和计算,只区分生命周期。
**通过 `preserveMovement` 叠加采集后滚动增量。** 该增量无法区分读者输入与同一次前插的原生锚定,叠加后可能重复补偿。
## Acceptance criteria
- 默认单阶段调用、延迟消费及 Turn 跳转共存,旧请求不能消费或覆盖新请求。
- auto 回退不会被普通事件恢复;触摸与内层滚动续接、manual 完成承诺和卸载清理都有定向验证。
- 一次补偿不注册持续观察、不撤销期间的读者滚动;既有持续保位和内层补偿不退化。
- 一次补偿使用既有屏幕位置恢复公式,不注册持续观察、不重复原生补偿;持续保位和内层补偿不退化。
- 距离读取使用缓存视口高度;原始滚动监听与消费准入不读取布局。
## Risks
**已知问题:`preserveMovement` 无法区分原生锚定与读者输入。** 共享补偿计算会加上采集后内外层滚动位置的变化。确定性的几何模型已确认:浏览器已为同一次前插完成锚定时,外层 `scrollTop` 为 `0.5`,或外层为 `0`、内层为 `40`,会进入一次补偿路径,把原生调整当成需要保留的移动,从而重复补偿。产生的额外位移是算法限制,不代表所有浏览器都会复现。本问题按仅报告处理,代码不变;独立真实浏览器验证仍待完成。
屏幕位置恢复使用原生锚定后测得的剩余位移,而不是叠加滚动位置增量。它不保留采集到应用之间任意输入造成的移动,也不保证惯性轨迹连续。外层近零位置、内层原生锚定以及前插附近到达的输入,都需要当前构建的浏览器验证。
显式导航与多个视图共享 Session,不能把 Chat 的自动等待条件放进全局事件源。手动操作若永远得不到可用定位条件仍可能等待;实际页面应验证取消、重连和无锚点结构。一次补偿的布局测量、内层浏览器锚定及异步内容增长需要当前构建的浏览器证据。
@@ -15,8 +15,8 @@
en: 2cbfd8cc05037895
zh: 024968506e2ac994
/agent-note-chat-history-prefetch-and-safe-consumption/proposal/position-and-status-presentation:
en: 1afb940b9b2a2fcc
zh: 8201614a80598e5b
en: 28d0c3b79f07ef07
zh: b62ac1c02f23e4fe
/agent-note-chat-history-prefetch-and-safe-consumption/proposal/scope-and-retained-decisions:
en: dd4eeadd2fccab4b
zh: e05d53e63cc44ddf
@@ -27,5 +27,5 @@
en: b3005052df98ab10
zh: c4bdf2bed8d23550
/agent-note-chat-history-prefetch-and-safe-consumption/risks:
en: 2016c51019518572
zh: e31e4e4ac09a2c5d
en: 4f1eac5c4dbd0b5e
zh: 9475ec9fa3bd9246
@@ -35,7 +35,7 @@ After fallback, scrolling, animation completion, and content notifications canno
### Position and status presentation
The actual conversation scrollport uses `overscroll-behavior-y: none` to suppress vertical boundary bounce and scroll chaining, without implementing a different momentum animation. A prepend at the top reuses the existing paging-position record and correction calculation, applies it once, and releases it; persistent preservation elsewhere retains its existing lifetime. Reader movement during the correction interval is preserved rather than restoring the position from request time.
The actual conversation scrollport uses `overscroll-behavior-y: none` to suppress vertical boundary bounce and scroll chaining, without implementing a different momentum animation. A prepend at the top reuses the existing paging-position record and correction calculation, applies it once, and releases it; persistent preservation elsewhere retains its existing lifetime. Both modes restore the screen position captured immediately before consumption with the same formula; they differ only in whether preservation remains active afterward. The one-shot path does not reconstruct intervening reader movement or restart momentum.
The history control keeps the same height across states. A network request shows Loading earlier; an active consumption intent without a held input shows Processing; automatic fallback or a held input shows Load earlier; failure shows Retry loading; consuming the final page shows Start of conversation. The control is excluded from native anchoring. Session `historyWasPartial` records that this instance has displayed incomplete history and survives component remounts and reconnects; a short Session that opens complete has no history row.
@@ -67,7 +67,7 @@ Do not add `flushSync` or change Conversation publication cadence, fold-batch ta
## Risks
**Known issue: duplicate anchoring compensation.** A deterministic geometry-model reproduction shows that one-shot correction can count native anchoring for the same page as reader movement and compensate twice: this occurs with an outer `scrollTop` of `0.5`, or with outer `0` and inner `40` when native anchoring has already moved the inner position. The algorithm is therefore not universally safe. This issue is recorded without a code fix; independent verification in actual browsers is pending. The mechanism is detailed in the [technical risks](2026-11-06-chat-history-consumption-details.md#risks).
One-shot correction restores a captured screen position rather than estimating reader velocity. Input or browser movement between capture and application can therefore affect the resulting motion; validation must cover the actual browser and input sequence. The shared formula does not add scroll-position deltas that could already include native anchoring. See the [technical risks](2026-11-06-chat-history-consumption-details.md#risks).
CSS feature support alone does not establish that native anchoring can act. Automatic prefetch waits for the first size observation, and the 500ms sample can let fast scrolling reach the top first. The synchronous geometry read after insertion is a cost of one-shot correction; its call site alone does not prove that it adds no layout. A stationary manual operation that can never obtain an anchor retains its completion intent and needs coverage for that structure.
@@ -35,7 +35,7 @@ Status: proposed
### 位置与状态展示
会话实际滚动容器设置 `overscroll-behavior-y: none`,关闭纵向边界回弹和滚动传递,不实现另一套惯性动画。顶部前插复用既有分页位置记录和补偿计算,只应用一次并释放;非顶部持续保位保持原生命周期。补偿期间发生的用户滚动保留,不把读者拉回请求发出时的位置。
会话实际滚动容器设置 `overscroll-behavior-y: none`,关闭纵向边界回弹和滚动传递,不实现另一套惯性动画。顶部前插复用既有分页位置记录和补偿计算,只应用一次并释放;非顶部持续保位保持原生命周期。两种模式用相同公式恢复消费前刚采集的屏幕位置,只区别于应用后是否继续保位。一次补偿不重建采集期间的读者移动,也不重新启动惯性。
历史控件各状态保持同高。网络请求显示“正在加载”;仍有消费意图且未按住输入时显示“正在处理”;自动回退或输入按住时显示“加载更早”;失败显示“重新加载”;最后一页消费完成后显示“已到会话开头”。控件不参与原生锚定。Session 的 `historyWasPartial` 记录本实例曾显示不完整历史,组件重挂载和重连保留此事实;首次打开即完整的短会话不添加历史行。
@@ -67,7 +67,7 @@ Status: proposed
## Risks
**已知问题:锚定重复补偿。** 确定性的几何模型复现表明,一次补偿可能把同一页已经发生的原生锚定当作读者移动,再补偿一次:外层 `scrollTop` 为 `0.5`,或外层为 `0`、内层为 `40` 且原生锚定已移动内层位置时会出现。该算法因此不能视为普遍安全。本问题仅记录,不修改代码;独立的真实浏览器验证仍待完成。机制见[技术风险](2026-11-06-chat-history-consumption-details.zh.md#risks)。
一次补偿恢复采集的屏幕位置,不估算读者速度。采集到应用之间的输入或浏览器移动可能影响最终运动,因此需要验证实际浏览器和输入序列。共享公式不叠加可能已包含原生锚定的滚动位置增量。见[技术风险](2026-11-06-chat-history-consumption-details.zh.md#risks)。
原生锚定适用性不能只由 CSS 支持检查保证。首次尺寸观察前不会自动预取;500ms 采样可能使高速滚动先到顶部。前插后的同步几何读取是一次补偿的成本,不能仅凭调用位置保证没有额外布局。静止手动消费若始终无法获得锚点,完成意图仍会等待,需要覆盖该特殊结构。
+2 -2
View File
@@ -36,8 +36,8 @@
en: e2b02942a55fb669
zh: a38bbee0cc69ae4e
/deepseek-ai-dsh-client-ui-chat/scroll-ownership:
en: a8e5c51345ef61b9
zh: 0e65169b79504da8
en: b26ab997d694ef90
zh: 1f8a16ba02bab301
/deepseek-ai-dsh-client-ui-chat/model-experience:
en: c17b4dd43a61c569
zh: f7414309810c3a08
+1 -1
View File
@@ -186,7 +186,7 @@ Within a process group, wheel, touchstart, and any pointerdown interrupt an acti
`useChatReading` owns follow policy, sampled reader input, and semantic memory; `useChatNavigation` owns turn jumps and requests preservation from the viewport. Reading gestures release the paging anchor, but composer clicks, typing, and non-scrolling keys retain it. A deferred history request captures its anchor at consumption rather than at request time. `useChatScroll` coordinates their committed inputs. Explicit navigation carries its measured landing into reading policy, so it does not rediscover the known target with a hit test.
History prefetch uses the existing 500ms reading sample and content/size notifications, with one distance check before requesting within two viewport heights. At most one page waits for consumption. Touch and inner scrolling retain automatic intent until release; active motion, pointer holds, or an unavailable anchor return automatic loading to the button without retrying the cached page. Explicit clicks retain intent until consumption, exhaustion, failure, or superseding navigation. Stationary consumption uses retained positioning; ordinary outer scrolling uses browser anchoring. At scrollTop ≤ 0.5, the first paging anchor supplies one content-displacement correction that retains intervening reader movement and then releases immediately. The actual Chat scrollport disables vertical overscroll bounce, without adding a scrolling animation. The history row keeps its height through loading, processing, retry, and exhaustion; initially complete Sessions omit it.
History prefetch uses the existing 500ms reading sample and content/size notifications, with one distance check before requesting within two viewport heights. At most one page waits for consumption. Touch and inner scrolling retain automatic intent until release; active motion, pointer holds, or an unavailable anchor return automatic loading to the button without retrying the cached page. Explicit clicks retain intent until consumption, exhaustion, failure, or superseding navigation. Stationary consumption uses retained positioning; ordinary outer scrolling uses browser anchoring. At scrollTop ≤ 0.5, the first paging anchor uses the same captured-screen-position restoration as persistent preservation, once, then releases immediately; it does not add scroll-position deltas that native anchoring may already have applied. The actual Chat scrollport disables vertical overscroll bounce, without adding a scrolling animation. The history row keeps its height through loading, processing, retry, and exhaustion; initially complete Sessions omit it.
Active-Turn highlighting is approximate: `readVisibleTurn` binary-searches the flow slot's direct Node/Group boxes (or the column's in standalone rendering) and retains the preceding candidate in gaps. It neither hit-tests the document nor searches Group members or all Turn markers. Empty Seats retain zero-height in-flow boxes so outer positions remain ordered without extra spacing. This lookup does not change semantic position capture or paging compensation.
+1 -1
View File
@@ -186,7 +186,7 @@ Chat 会在历史前插与 renderer 重新挂载时恢复语义锚点,并且
`useChatReading` 负责跟随策略、读者输入采样和语义位置记忆;`useChatNavigation` 负责轮次跳转,并向视口请求位置保持。阅读手势释放分页锚点,composer 内的点击、打字和非滚动按键则保留锚点。延迟消费的历史请求在消费时采集锚点,不在发请求时采集。`useChatScroll` 协调已提交的输入。显式导航把测得的落点交给阅读策略,因此无需通过命中测试重新寻找已知目标。
历史预取复用已有 500ms 阅读采样及内容/尺寸通知,在请求前确认距顶部两屏以内,最多一页等待消费。触摸和内层滚动保留自动意图至释放;动画、指针按住或无法取得锚点使自动加载退回按钮,不自动重试缓存页。明确点击保留意图,直到消费、到头、失败或被新导航取代。静止消费使用保位,普通外层滚动使用浏览器锚定;scrollTop ≤ 0.5 时用首条分页锚点补偿一次内容位移,保留期间的读者滚动,随后立即释放。实际 Chat 滚动区关闭纵向越界回弹,不新增滚动动画。历史行在加载、处理、重试和到头时保持高度,首次打开就完整的 Session 不显示该行。
历史预取复用已有 500ms 阅读采样及内容/尺寸通知,在请求前确认距顶部两屏以内,最多一页等待消费。触摸和内层滚动保留自动意图至释放;动画、指针按住或无法取得锚点使自动加载退回按钮,不自动重试缓存页。明确点击保留意图,直到消费、到头、失败或被新导航取代。静止消费使用保位,普通外层滚动使用浏览器锚定;scrollTop ≤ 0.5 时,首条分页锚点与持续保位共用采集屏幕位置的恢复公式,只应用一次便立即释放;不再叠加可能已由原生锚定产生的滚动位置增量。实际 Chat 滚动区关闭纵向越界回弹,不新增滚动动画。历史行在加载、处理、重试和到头时保持高度,首次打开就完整的 Session 不显示该行。
活跃轮次高亮采用近似定位:`readVisibleTurn` 对 flow 插槽的直属 Node/Group 布局盒二分(独立渲染时使用正文容器的直属布局盒),落在间隙时保留前方候选。它不做文档命中测试,也不查询 Group 成员或全部 Turn 标记。空 Seat 保留零高度的流内布局盒,使外层位置有序且不增加间距。这种定位不改变语义位置捕获或分页补偿。
@@ -67,7 +67,7 @@ interface ClosingLayout {
interface PagingPosition {
readonly row: HTMLElement
readonly position: ChatScrollPosition
readonly group: { readonly body: HTMLElement; readonly content: HTMLElement; readonly top: number; readonly scrollTop: number } | null
readonly group: { readonly body: HTMLElement; readonly content: HTMLElement; readonly top: number } | null
}
const READING_INTENTS = ['wheel', 'touchstart', 'pointerdown', 'keydown', 'beforematch'] as const
@@ -830,8 +830,7 @@ export class ChatViewport {
const body = row.closest<HTMLElement>('[data-step-process-body]')
const content = body?.querySelector<HTMLElement>('[data-step-process-content]')
const group = body === null || content == null ? null
: { body, content, top: previousGroup?.top ?? top - body.getBoundingClientRect().top,
scrollTop: previousGroup?.body === body ? previousGroup.scrollTop : body.scrollTop }
: { body, content, top: previousGroup?.top ?? top - body.getBoundingClientRect().top }
return {
row, group,
position: position ?? {
@@ -880,7 +879,7 @@ export class ChatViewport {
return null
}
if (paging !== this.paging) this.retainPaging(paging)
return this.applyPaging(paging, false)
return this.applyPaging(paging)
}
private resolvePaging(paging: PagingPosition | null): PagingPosition | null {
@@ -896,17 +895,15 @@ export class ChatViewport {
return paging.row.closest('[hidden]') !== null || paging.row.matches(':empty') ? null : paging
}
/** Content correction includes reader movement since capture; screen preservation restores the captured position. */
private applyPaging(paging: PagingPosition, preserveMovement: boolean): ViewportLanding | null {
/** Restore the captured screen position; native anchoring already applied to this change needs no further correction. */
private applyPaging(paging: PagingPosition): ViewportLanding | null {
const elements = this.elements
if (elements === null) return null
const { row, group, position } = paging
let innerMovement = 0
if (group !== null && group.body.contains(row)) {
const top = row.getBoundingClientRect().top - group.body.getBoundingClientRect().top
const metrics = scrollMetrics(group.body)
if (preserveMovement) innerMovement = metrics.top - group.scrollTop
const target = Math.max(0, Math.min(metrics.floor, metrics.top + top - group.top + innerMovement))
const target = Math.max(0, Math.min(metrics.floor, metrics.top + top - group.top))
if (metrics.top !== target) {
const follow = ScrollFollow.forElement(group.body)
if (follow === undefined) group.body.scrollTop = target
@@ -919,8 +916,7 @@ export class ChatViewport {
const metrics = this.metrics()
if (metrics === null) return null
const top = row.getBoundingClientRect().top - elements.scroller.getBoundingClientRect().top
const movement = preserveMovement ? metrics.top - position.scrollTop + innerMovement : 0
const target = metrics.top + top - position.anchorTop + movement
const target = metrics.top + top - position.anchorTop
return this.write(target, metrics, null, { key: position.anchorKey, top })
}
@@ -1052,7 +1048,7 @@ export class ChatViewport {
const pending = this.historyPrepend
this.historyPrepend = null
const paging = this.resolvePaging(pending)
return paging === null ? null : this.applyPaging(paging, true)
return paging === null ? null : this.applyPaging(paging)
}
private readonly onHistoryScroll = (event: Event): void => {
@@ -121,7 +121,7 @@ it('uses a collapsed group paging anchor when no ordinary content row is visible
expect(h.viewport.preserving).toBe(false)
})
it('keeps reader movement during a one-shot prepend without retaining paging ownership', () => {
it('restores the captured screen position once without retaining paging ownership', () => {
const h = fixture()
const row = h.row(h.column, 'old', 0)
expect(h.viewport.beginHistoryPrepend()).toBe(true)
@@ -129,8 +129,8 @@ it('keeps reader movement during a one-shot prepend without retaining paging own
h.column.scrollTop = 25
h.prepend(120)
h.viewport.finishHistoryPrepend()
expect(h.column.scrollTop).toBe(145)
expect(row.getBoundingClientRect().top).toBe(-25)
expect(h.column.scrollTop).toBe(120)
expect(row.getBoundingClientRect().top).toBe(0)
expect(h.viewport.preserving).toBe(false)
})
@@ -534,7 +534,7 @@ it.each([
expect(h.row.getBoundingClientRect().top).toBe(top)
})
it('applies one-shot inner compensation without subscribing or undoing reader movement', () => {
it('restores the captured inner and outer screen position once without subscribing', () => {
const h = nestedFixture(600, 400)
h.scroller.scrollTop = 80
h.body.scrollTop = 40
@@ -546,14 +546,14 @@ it('applies one-shot inner compensation without subscribing or undoing reader mo
h.scroller.scrollTop = 90
h.prepend(200)
h.viewport.finishHistoryPrepend()
expect(h.body.scrollTop).toBe(260)
expect(h.scroller.scrollTop).toBe(90)
expect(h.row.getBoundingClientRect().top).toBe(screenTop - 30)
expect(h.body.scrollTop).toBe(240)
expect(h.scroller.scrollTop).toBe(80)
expect(h.row.getBoundingClientRect().top).toBe(screenTop)
expect(h.observed.has(h.content)).toBe(false)
h.prepend(20)
h.resize()
expect(h.body.scrollTop).toBe(260)
expect(h.scroller.scrollTop).toBe(90)
expect(h.body.scrollTop).toBe(240)
expect(h.scroller.scrollTop).toBe(80)
})
it('resolves a remounted one-shot anchor without entering retained paging', () => {
@@ -565,8 +565,37 @@ it('resolves a remounted one-shot anchor without entering retained paging', () =
h.column.scrollTop = 25
h.prepend(120)
h.viewport.finishHistoryPrepend()
expect(h.column.scrollTop).toBe(145)
expect(replacement.getBoundingClientRect().top).toBe(-25)
expect(h.column.scrollTop).toBe(120)
expect(replacement.getBoundingClientRect().top).toBe(0)
expect(h.viewport.preserving).toBe(false)
})
it('does not repeat native outer anchoring during a near-zero one-shot prepend', () => {
const h = fixture()
const row = h.row(h.column, 'old', 0)
h.column.scrollTop = 0.5
const top = row.getBoundingClientRect().top
expect(h.viewport.beginHistoryPrepend()).toBe(true)
h.prepend(120)
// Model the browser's adjustment before the layout effect reads the new geometry.
h.column.scrollTop = 120.5
h.viewport.finishHistoryPrepend()
expect(h.column.scrollTop).toBe(120.5)
expect(row.getBoundingClientRect().top).toBe(top)
})
it('does not repeat native inner anchoring when the outer scroller is at zero', () => {
const h = nestedFixture(600, 400)
h.body.scrollTop = 40
const top = h.row.getBoundingClientRect().top
expect(h.viewport.beginHistoryPrepend()).toBe(true)
h.prepend(200)
// Same ordering as the Chromium regression: native inner adjustment precedes our correction.
h.body.scrollTop = 240
h.viewport.finishHistoryPrepend()
expect(h.body.scrollTop).toBe(240)
expect(h.scroller.scrollTop).toBe(0)
expect(h.row.getBoundingClientRect().top).toBe(top)
expect(h.viewport.preserving).toBe(false)
})