Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix(web): preserve bottom follow after end-clamped input (#922)

Genere4d87183e6a8
diff --git a/src/web/src/hooks/community/use-scroll-anchor.repin.dom.test.ts b/src/web/src/hooks/community/use-scroll-anchor.repin.dom.test.ts
index 04597b435..be831bc92 100644
--- a/src/web/src/hooks/community/use-scroll-anchor.repin.dom.test.ts
+++ b/src/web/src/hooks/community/use-scroll-anchor.repin.dom.test.ts
@@ -1179,6 +1179,61 @@ describe("locked native adapter and existing message scroll owner", () => {
runFrames(5)
expect(frames).not.toHaveBeenCalled()
})
+ it.each(["wheel", "ArrowDown", "PageDown", "End", " ", "pointer", "touch"])("follows a peer after settled-end %s input without a scroll event", input => {
+ const h = mount({}, input === "pointer")
+ const native = scrollFixture.latest.virtualizer
+ const end = vi.spyOn(native, "scrollToEnd")
+ const scroll = vi.fn()
+ h.root.addEventListener("scroll", scroll)
+ expect(native.isAtEnd(1)).toBe(true)
+ expect(native.isScrolling).toBe(false)
+ expect(scrollFixture.latest.readPositionReady).toBe(true)
+ if (input === "wheel") fireEvent.wheel(h.root, { deltaY: 80 })
+ else if (input === "pointer") {
+ const down = new Event("pointerdown", { bubbles: true })
+ Object.defineProperty(down, "pointerId", { value: 41 })
+ fireEvent(h.root, down)
+ const up = new Event("pointerup", { bubbles: true })
+ Object.defineProperty(up, "pointerId", { value: 41 })
+ fireEvent(document, up)
+ } else if (input === "touch") {
+ fireEvent.touchStart(h.root, { touches: [{ identifier: 1, clientY: 200 }] })
+ fireEvent.touchEnd(h.root, { touches: [] })
+ } else fireEvent.keyDown(h.root, { key: input })
+ expect(scroll).not.toHaveBeenCalled()
+ expect(native.isAtEnd(1)).toBe(true)
+ h.update({ items: [...h.input.items, message("received")] })
+ expect(end).toHaveBeenCalledOnce()
+ expect(h.root.querySelector('[data-msg-id="received"]')).not.toBeNull()
+ expect(h.root.scrollHeight - h.root.clientHeight - h.root.scrollTop).toBeLessThanOrEqual(1)
+ h.root.removeEventListener("scroll", scroll)
+ })
+ it.each(["wheel", "ArrowUp", "PageUp", "Home", "shift-space", "pointer", "touch", "unregistered-touch"])("protects %s departure before a physical scroll event", input => {
+ const h = mount()
+ const native = scrollFixture.latest.virtualizer
+ const end = vi.spyOn(native, "scrollToEnd")
+ const before = bodyTop(h.root, "m13")
+ if (input === "wheel") fireEvent.wheel(h.root, { deltaY: -20 })
+ else if (input === "pointer") {
+ const down = new Event("pointerdown", { bubbles: true })
+ Object.defineProperty(down, "pointerId", { value: 41 })
+ fireEvent(h.root, down)
+ const unrelated = new Event("pointerup", { bubbles: true })
+ Object.defineProperty(unrelated, "pointerId", { value: 42 })
+ fireEvent(document, unrelated)
+ } else if (input === "touch") {
+ fireEvent.touchStart(h.root, { touches: [{ identifier: 1, clientY: 200 }, { identifier: 2, clientY: 210 }] })
+ fireEvent.touchEnd(h.root, { touches: [{ identifier: 2, clientY: 210 }] })
+ } else if (input === "unregistered-touch") {
+ fireEvent.wheel(h.root, { deltaY: -20 })
+ fireEvent.touchEnd(h.root, { touches: [] })
+ } else fireEvent.keyDown(h.root, { key: input === "shift-space" ? " " : input, shiftKey: input === "shift-space" })
+ expect(native.isAtEnd(1)).toBe(true)
+ h.update({ items: [...h.input.items, message("received")] })
+ expect(end).not.toHaveBeenCalled()
+ expect(bodyTop(h.root, "m13")).toBe(before)
+ expect(h.root.scrollHeight - h.root.clientHeight - h.root.scrollTop).toBeGreaterThan(1)
+ })
it("follows a new self-send once and retains its stable display key on canonical acknowledgement", () => {
const h = mount({ viewerUserId: "me" })
h.move(300)
diff --git a/src/web/src/hooks/community/use-scroll-anchor.ts b/src/web/src/hooks/community/use-scroll-anchor.ts
index 319df4692..3f9d22082 100644
--- a/src/web/src/hooks/community/use-scroll-anchor.ts
+++ b/src/web/src/hooks/community/use-scroll-anchor.ts
@@ -865,24 +865,42 @@ export function useScrollAnchor({
}
scheduleGeometry()
}
- const onUserIntent = () => {
- userScrolledAwayRef.current = true
+ const restoreEndEligibility = () => {
+ const input = userInputRef.current
+ const native = virtualizerRef.current
+ if (input.touch || input.pointers.size > 0 || positionKind.get() !== "idle" || !readReady.get()
+ || nativeOrigin.get() === currentItemsRef.current[0]?.key) return
+ const geometry = readGeometry()
+ if (!geometry || geometry.isScrolling || !native?.isAtEnd(1)
+ || Math.abs(Math.max(0, geometry.scrollHeight - geometry.clientHeight) - geometry.scrollTop) > 1) return
+ wasAtEndRef.current = true
+ userScrolledAwayRef.current = false
+ }
+ const onUserIntent = (towardEnd = false) => {
releasePosition(true)
userScrolledAwayRef.current = true
if (root.scrollTop <= 1) holdNativeOrigin(currentItemsRef.current[0]?.key ?? null)
+ if (towardEnd) restoreEndEligibility()
+ }
+ const onWheel = (event: WheelEvent) => {
+ if (event.deltaY !== 0) onUserIntent(event.deltaY > 0)
}
- const onWheel = (event: WheelEvent) => { if (event.deltaY !== 0) onUserIntent() }
const onKeyDown = (event: KeyboardEvent) => {
- if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "].includes(event.key)) onUserIntent()
+ if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "].includes(event.key)) {
+ onUserIntent(["ArrowDown", "PageDown", "End"].includes(event.key) || (event.key === " " && !event.shiftKey))
+ }
}
const onTouchStart = () => { userInputRef.current.touch = true; onUserIntent() }
const onTouchEnd = (event: TouchEvent) => {
+ const registered = userInputRef.current.touch
userInputRef.current.touch = event.touches.length > 0
+ if (registered) restoreEndEligibility()
scheduleGeometry()
}
const onPointerDown = (event: PointerEvent) => { userInputRef.current.pointers.add(event.pointerId); onUserIntent() }
const onPointerUp = (event: PointerEvent) => {
if (!userInputRef.current.pointers.delete(event.pointerId)) return
+ restoreEndEligibility()
scheduleGeometry()
}
const onBlur = () => {
diff --git a/src/web/src/test/e2e-ui/55-message-scroll-characterization.spec.ts b/src/web/src/test/e2e-ui/55-message-scroll-characterization.spec.ts
index 0b8332869..2f8daaf8d 100644
--- a/src/web/src/test/e2e-ui/55-message-scroll-characterization.spec.ts
+++ b/src/web/src/test/e2e-ui/55-message-scroll-characterization.spec.ts
@@ -717,6 +717,45 @@ test.describe.serial("message scroll characterization", () => {
await newest.dispose()
})
+ test("peer receives follow after clamped bottom input without movement", async ({ asUser }) => {
+ test.setTimeout(120_000)
+ const channelId = await seedChannel("alice", serverId, `scroll-bottom-input-${Date.now()}`)
+ await seedProfile(channelId, 18)
+ let tailId = await seedMessage("bob", channelId, "bottom input start\n[keyboard target](https://example.com)")
+ await setReadCheckpoint(channelId, tailId)
+ const alice = await asUser("alice")
+ await alice.page.setViewportSize(VIEWPORT)
+ const proxy = await proxyCommunityWebSockets(alice.context)
+ await gotoAfterUserWsAuth(alice.page, `/c/channels/${serverId}/${channelId}`)
+ const scroller = alice.page.getByTestId(tid.messageScroller)
+ await expect(scroller.locator('[data-message-list-content]')).toHaveAttribute("data-read-position-ready", "true")
+ for (const input of ["click", "wheel", "ArrowDown", "PageDown", "End", "Space"]) {
+ await waitForStableTail(scroller, `bottom-${input}`)
+ if (input !== "click" && input !== "wheel") {
+ await alice.page.getByTestId(tid.message(tailId)).getByRole("link", { name: "Link: https://example.com/" }).focus()
+ }
+ const before = await waitForCommittedGeometry(scroller)
+ expect(before.distanceToEnd).toBeLessThanOrEqual(1)
+ const box = await scroller.boundingBox()
+ expect(box).not.toBeNull()
+ await alice.page.mouse.move(box!.x + box!.width / 2, box!.y + box!.height - 16)
+ if (input === "click") await alice.page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height - 16)
+ else if (input === "wheel") await alice.page.mouse.wheel(0, 120)
+ else await alice.page.keyboard.press(input)
+ const after = await waitForCommittedGeometry(scroller)
+ expect(after.distanceToEnd).toBeLessThanOrEqual(1)
+ expect(Math.abs(after.scrollTop - before.scrollTop)).toBeLessThanOrEqual(1)
+ const body = `bottom input ${input} ${Date.now()}\n[keyboard target](https://example.com)`
+ tailId = await seedMessage("carol", channelId, body)
+ await expect.poll(() => proxy.frames.filter(frame => communityFrameEvents(frame).some(event =>
+ event.type === "community:message.create" && event.channelId === channelId && event.message?.id === tailId,
+ )).length).toBe(1)
+ await expect(alice.page.getByTestId(tid.message(tailId))).toBeVisible()
+ await waitForStableTail(scroller, `received-${input}`)
+ await expect(alice.page.getByTestId(tid.scrollToPresent)).toHaveCount(0)
+ }
+ })
+
test("remote receive states and sustained upward input produce diagnostic traces", async ({ asUser }, testInfo) => {
test.setTimeout(180_000)
const alice = await asUser("alice")