Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(channels): stop iOS channel scrolling at the latest message (#9345)
Peter Chinmanc0510ae4543f
diff --git a/apps/web/src/features/channel/Channel/ThreadList.tsx b/apps/web/src/features/channel/Channel/ThreadList.tsxindex b095d10da3..0936ee9eaf 100644--- a/apps/web/src/features/channel/Channel/ThreadList.tsx+++ b/apps/web/src/features/channel/Channel/ThreadList.tsx@@ -161,22 +161,30 @@ export function ThreadList(props: ThreadListProps) {const batchHeights = new Map<Element, number>();let applyingBatch = false;let deferredScroll: Parameters<ScrollToFn> | undefined;+ // Rows shift by the gesture adjustment. The sizer's end moves with them, so+ // native scrolling stops at the latest row instead of blank space past it.+ let gestureAdjustment = 0;+ const sizerHeight = (total: number) =>+ Math.max(viewportSize(), total - gestureAdjustment);const scrollCompensation =isSafari || isIOS? createScrollCompensation({getElement: () => scrollEl(),setAdjustment: (adjustment) => {+ gestureAdjustment = adjustment;if (!contentRef) return;contentRef.style.setProperty('--channel-scroll-adjustment',`${adjustment}px`);- // Shifted rows must not change the logical scroll extent.- contentRef.style.overflow = adjustment === 0 ? '' : 'clip';},writeOffset: (offset) => {const element = scrollEl();if (!element) return;+ // Restore the logical extent before the offset replaces the adjustment.+ if (contentRef) {+ contentRef.style.height = `${sizerHeight(virtualizer.getTotalSize())}px`;+ }writingScroll = true;try {element.scrollTo({ top: offset });@@ -381,21 +389,19 @@ export function ThreadList(props: ThreadListProps) {});function writeScroll(...[offset, options, instance]: Parameters<ScrollToFn>) {- // Size corrections happen before the Solid adapter publishes its new- // total. Commit the sizer first so the browser cannot clamp the requested- // scroll to the old range (especially with padding below a growing row).- if (contentRef) {- contentRef.style.height = `${Math.max(viewportSize(), instance.getTotalSize())}px`;- }// WebKit ends native momentum on scrollTo writes. Keep TanStack's logical// offset, but counter-shift the rows until wheel/touch scrolling settles.// Explicit navigation finishes compensation before calculating its target.- if (+ const deferred =lifecycle.isReady() &&- scrollCompensation?.defer(offset + (options.adjustments ?? 0))- ) {- return;+ !!scrollCompensation?.defer(offset + (options.adjustments ?? 0));+ // Size corrections happen before the Solid adapter publishes its new+ // total. Commit the sizer first so the browser cannot clamp the requested+ // scroll to the old range (especially with padding below a growing row).+ if (contentRef) {+ contentRef.style.height = `${sizerHeight(instance.getTotalSize())}px`;}+ if (deferred) return;writingScroll = true;try {elementScroll(offset, options, instance);@@ -524,11 +530,13 @@ export function ThreadList(props: ThreadListProps) {if (!el) return;// This microtask runs after synchronous row measurements, before paint.lifecycle.send('layout');- const distanceFromTop = logicalScrollOffset(el.scrollTop);+ const scrollTop = el.scrollTop;+ const distanceFromTop = logicalScrollOffset(scrollTop);// The virtualizer's cached offset can trail scrollTop: this publish may run// in the microtask before its own scroll listener records the new position.+ // The sizer excludes the gesture adjustment, so compare native positions.const distanceFromBottom = Math.max(- el.scrollHeight - el.clientHeight - distanceFromTop,+ el.scrollHeight - el.clientHeight - scrollTop,0);// WebKit cannot move the native top boundary during a fling without a@@ -653,7 +661,7 @@ export function ThreadList(props: ThreadListProps) {style={{position: 'relative',width: '100%',- height: `${Math.max(viewportSize(), virtualizer.getTotalSize())}px`,+ height: `${sizerHeight(virtualizer.getTotalSize())}px`,}}><Key each={virtualItems()} by="key">diff --git a/apps/web/src/features/channel/Channel/tests/thread-list-pagination.test.tsx b/apps/web/src/features/channel/Channel/tests/thread-list-pagination.test.tsxindex f933e96e37..2be6652af4 100644--- a/apps/web/src/features/channel/Channel/tests/thread-list-pagination.test.tsx+++ b/apps/web/src/features/channel/Channel/tests/thread-list-pagination.test.tsx@@ -189,6 +189,32 @@ describe('history loading ahead of scrolling', () => {expect(f.paginate).toHaveBeenCalledTimes(3);});+ it('ends native scrolling at the latest message while a gesture shifts the rows', async () => {+ const f = setup();+ await waitFor(() => expect(f.paginate).toHaveBeenCalledOnce());+ expect(f.element.scrollTop).toBe(1520);+ f.element.dispatchEvent(new TouchEvent('touchstart'));+ // History arriving mid-gesture shifts the rows instead of writing scrollTop.+ f.prepend(10);+ f.element.dispatchEvent(new Event('scroll'));+ await waitFor(() =>+ expect(f.onScroll).toHaveBeenLastCalledWith(+ expect.objectContaining({ distanceFromTop: 2480 }),+ expect.anything()+ )+ );+ expect(f.element.scrollTop).toBe(1520);+ // Scrolling down from here would only reveal blank space below the rows.+ expect(f.element.scrollHeight - f.element.clientHeight).toBe(1520);+ expect(f.onScroll).toHaveBeenLastCalledWith(+ expect.objectContaining({ distanceFromBottom: 0, isNearBottom: true }),+ expect.anything()+ );+ f.element.dispatchEvent(new TouchEvent('touchend', { touches: [] }));+ await waitFor(() => expect(f.element.scrollTop).toBe(2480));+ expect(f.element.scrollHeight).toBe(30 * 96);+ });+it('does not repeat a request for an unchanged boundary', async () => {const f = setup();await waitFor(() => expect(f.paginate).toHaveBeenCalledOnce());@@ -214,6 +240,13 @@ describe('history loading ahead of scrolling', () => {});describe('server acknowledgement scroll anchoring', () => {+ // Acknowledgements arrive outside gestures, where WebKit writes scrollTop+ // directly too. The mocked scroll events would otherwise start gesture+ // compensation, which hides the offset these tests check.+ beforeEach(() => {+ platform.safari = false;+ });+it.each([0, 10])('preserves the pin only when already at the end (%ipx gap)',async (gap) => {diff --git a/apps/web/src/features/channel/docs/sticky-scrolling.md b/apps/web/src/features/channel/docs/sticky-scrolling.mdindex 0cc932e53a..33bfecc81a 100644--- a/apps/web/src/features/channel/docs/sticky-scrolling.md+++ b/apps/web/src/features/channel/docs/sticky-scrolling.md@@ -70,7 +70,10 @@ once 150ms pass without input or scrolling and `scrollTop` has not moved in thatthe adjustment is removed and committed to the DOM offset in the same task. A busymain thread can delay scroll events beyond 150ms while momentum continues, so thetimer alone is not proof that scrolling stopped.-The sizer retains its logical height and clips shifted overflow during this period.+The sizer's height excludes the adjustment during this period, so its end moves with+the shifted rows: native scrolling stops at the latest message instead of continuing+into blank space below it (or stopping short of it), and the distance to the bottom+compares native positions.Scroll boundaries follow the same rule: momentum bounces there, and a finger can holdthe list against an edge. Explicit message, reply, latest, and pinned viewport/insetnavigation flush the adjustment before computing targets.diff --git a/docs/agent-guide/channels.md b/docs/agent-guide/channels.mdindex 5c7e16a1c6..f59843fbdd 100644--- a/docs/agent-guide/channels.md+++ b/docs/agent-guide/channels.md@@ -706,6 +706,9 @@ Very long flings or slow responses can still exhaust the available scroll range.In the iOS app, fling repeatedly through a long channel, starting each fling beforethe previous one's momentum ends, then let it settle. The messages must not jump whenscrolling comes to rest, nor when it bounces or is held against the top of loaded history.+In a channel opened for the first time, fling up through unmeasured history and+straight back down: scrolling must stop at the latest message, never in blank space+below it.Inline document mentions should show their stored title before entering the viewportand while preview requests are pending. With a slow preview response, check that a