The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 15:45 UTC
fix(web): screen readers can wrap to the first and last message of a long thread (#23780)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: nibarAhmed <61316519+nibarAhmed@users.noreply.github.com> Co-authored-by: maria-rcks <maria@kuuro.net>
shivam committed
Oct 27, 2026 at 03:44 UTC
6838e31b9c2942fa395fc05e27276776cd33dde5
5 files changed
+533
-26
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+144
-2
@@ -15,7 +15,7 @@ import { describe, expect, it, vi } from "vite-plus/test";
15
16
import "~/index.css";
17
18
-import { act, render } from "../../../test/render";
18
+import { act, fakeTimers, render } from "../../../test/render";
19
import { MessagesTimeline } from "./MessagesTimeline";
20
import { makeStreamingTimelineFixture } from "../../test-fixtures";
21
import { deriveTimelineEntriesFromVisibleTurnItems } from "../../session-logic";
@@ -201,6 +201,146 @@ describe("MessagesTimeline messages", () => {
201
expect(maxNestedCommits).toBeLessThan(20);
202
});
203
204
+ it("keeps the first and last message headings reachable from either end", async () => {
205
+ setup();
206
+ const props = baseProps();
207
+ // Folded messages at both ends: their headings must not live inside the fold.
208
+ const entries = Array.from({ length: 120 }, (_, index) =>
209
+ index === 0
210
+ ? message("First turn", { scheduledTaskId: TASK_ID }, "turn-0")
211
+ : index === 119
212
+ ? message(
213
+ "Last turn",
214
+ { createdBy: "agent", senderThreadId: ThreadId.make("thread-sender") },
215
+ "turn-119",
216
+ )
217
+ : message(
218
+ `Turn ${index}:\n\n${"x ".repeat(200)}`,
219
+ { role: index % 2 === 0 ? "user" : "assistant" },
220
+ `turn-${index}`,
221
+ ),
222
+ );
223
+ await using screen = await renderElement(
224
+ <MessagesTimeline {...props} timelineEntries={entries} />,
225
+ );
226
+ const headings = () => [...screen.container.querySelectorAll("h3")];
227
+ const headingFor = (text: string) =>
228
+ headings().find((heading) => heading.parentElement?.textContent?.includes(text));
229
+ const viewport = props.listRef.current!.getScrollableNode()!;
230
+ // A screen reader scrolls the heading it moves to into view.
231
+ const expectHeadingInView = async (text: string, neighbour: string) => {
232
+ await act(() => headingFor(text)!.scrollIntoView({ block: "start" }));
233
+ await vi.waitFor(() => expect(screen.text()).toContain(neighbour));
234
+ const row = headingFor(text)!.parentElement!.getBoundingClientRect();
235
+ const view = viewport.getBoundingClientRect();
236
+ expect(row.top).toBeLessThan(view.bottom);
237
+ expect(row.bottom).toBeGreaterThan(view.top);
238
+ };
239
+
240
+ await vi.waitFor(() => expect(screen.text()).toContain("Turn 118:"));
241
+ expect(screen.text()).not.toContain("Turn 60:");
242
+ // Wrapping follows DOM order, so the ends must also sit first and last.
243
+ await vi.waitFor(() => {
244
+ expect(headings()[0]).toBe(headingFor("First turn"));
245
+ expect(headings().at(-1)).toBe(headingFor("Last turn"));
246
+ });
247
+
248
+ await expectHeadingInView("First turn", "Turn 1:");
249
+ expect(headingFor("Last turn")).toBeDefined();
250
+ await expectHeadingInView("Last turn", "Turn 118:");
251
+ });
252
+
253
+ it("keeps rows in item order after a reload or thread switch, before any timer runs", async () => {
254
+ setup();
255
+ // NVDA's browse mode keeps the first DOM order it reads, so a timer that sorts rows later is too late.
256
+ using _timers = fakeTimers();
257
+ const thread = (name: string) =>
258
+ Array.from({ length: 120 }, (_, index) =>
259
+ message(
260
+ `${name} turn ${index}:\n\n${"x ".repeat(200)}`,
261
+ { role: index % 2 === 0 ? "user" : "assistant" },
262
+ `${name}-${index}`,
263
+ ),
264
+ );
265
+ const props = baseProps();
266
+ await using screen = await renderElement(
267
+ <MessagesTimeline {...props} timelineEntries={thread("A")} />,
268
+ );
269
+ const turnsInDomOrder = () =>
270
+ [...screen.container.querySelectorAll("h3")].map((heading) =>
271
+ Number(/turn (\d+):/.exec(heading.parentElement?.textContent ?? "")?.[1]),
272
+ );
273
+ const expectItemOrder = () => {
274
+ const turns = turnsInDomOrder();
275
+ expect(turns).toEqual(turns.toSorted((a, b) => a - b));
276
+ };
277
+
278
+ expect(screen.text()).toContain("A turn 118:");
279
+ expect(turnsInDomOrder()).toContain(0);
280
+ expectItemOrder();
281
+
282
+ await screen.rerender(
283
+ <MessagesTimeline
284
+ {...props}
285
+ routeThreadKey={`${props.routeThreadKey}-other`}
286
+ timelineEntries={thread("B")}
287
+ />,
288
+ );
289
+ expect(screen.text()).toContain("B turn 118:");
290
+ expect(screen.text()).not.toContain("A turn");
291
+ expectItemOrder();
292
+ });
293
+
294
+ it("puts rows back in item order soon after a continuous scroll stops", async () => {
295
+ setup();
296
+ const props = baseProps();
297
+ await using screen = await renderElement(
298
+ <MessagesTimeline
299
+ {...props}
300
+ timelineEntries={Array.from({ length: 120 }, (_, index) =>
301
+ message(
302
+ `Turn ${index}:\n\n${"x ".repeat(200)}`,
303
+ { role: index % 2 === 0 ? "user" : "assistant" },
304
+ `turn-${index}`,
305
+ ),
306
+ )}
307
+ />,
308
+ );
309
+ await vi.waitFor(() => expect(screen.text()).toContain("Turn 118:"));
310
+ using _timers = fakeTimers();
311
+ const turnsInDomOrder = () =>
312
+ [...screen.container.querySelectorAll("h3")].map((heading) =>
313
+ Number(/Turn (\d+):/.exec(heading.parentElement?.textContent ?? "")?.[1]),
314
+ );
315
+ const viewport = props.listRef.current!.getScrollableNode()!;
316
+
317
+ const scroll = async (by: number) => {
318
+ for (let step = 0; step < 40; step++) {
319
+ await act(() => {
320
+ viewport.scrollTop += by;
321
+ viewport.dispatchEvent(new Event("scroll"));
322
+ vi.advanceTimersByTime(16);
323
+ });
324
+ }
325
+ // Wrapping right after a scroll must still reach the first and last message.
326
+ expect(turnsInDomOrder()[0]).toBe(0);
327
+ expect(turnsInDomOrder().at(-1)).toBe(119);
328
+ };
329
+
330
+ await act(() => {
331
+ viewport.scrollTop = 0;
332
+ viewport.dispatchEvent(new Event("scroll"));
333
+ vi.advanceTimersByTime(300);
334
+ });
335
+ await scroll(300);
336
+ expect(turnsInDomOrder().filter((turn) => turn > 0 && turn < 100).length).toBeGreaterThan(0);
337
+ await scroll(-300);
338
+
339
+ await act(() => vi.advanceTimersByTime(300));
340
+ const turns = turnsInDomOrder();
341
+ expect(turns).toEqual(turns.toSorted((a, b) => a - b));
342
+ });
343
+
344
it("preserves XML-like tags and comparisons in user messages as text", async () => {
345
const source = [
346
'Without reading a file, do you have <global-agent-instructions scope="workspace">',
@@ -576,6 +716,8 @@ describe("MessagesTimeline attachments", () => {
716
const props = baseProps();
717
await using screen = await renderTimeline(
718
[
719
+ // The first message row is always mounted, so the recordings go in the second.
720
+ message("Start of the thread.", { role: "user" }, "opening"),
721
message(
722
"Two recordings.",
723
{
@@ -601,7 +743,7 @@ describe("MessagesTimeline attachments", () => {
743
await vi.waitFor(
744
async () => {
745
await act(() => {
604
- void props.listRef.current?.scrollToIndex({ index: 0, animated: false });
746
+ void props.listRef.current?.scrollToIndex({ index: 1, animated: false });
747
});
748
expect(screen.container.querySelectorAll("audio")).toHaveLength(2);
749
},
apps/web/src/components/chat/MessagesTimeline.tsx
+10
@@ -743,7 +743,13 @@ const ConversationTimeline = memo(function ConversationTimeline({
743
setFullscreenAppRowId((current) => (fullscreen ? rowId : current === rowId ? null : current));
744
};
745
const alwaysRenderIndices = restoringAlwaysRender?.indices ?? [];
746
+ // Screen readers can only reach headings in the DOM. Keeping the first and
747
+ // last messages mounted lets heading navigation wrap to either end.
748
+ const firstMessageRow = rows.find(isMessageRow);
749
+ const lastMessageRow = rows.findLast(isMessageRow);
750
const alwaysRenderKeys = [
751
+ ...(firstMessageRow ? [firstMessageRow.id] : []),
752
+ ...(lastMessageRow && lastMessageRow !== firstMessageRow ? [lastMessageRow.id] : []),
753
...(citationAlwaysRender?.keys ?? []),
754
...(fullscreenAppRowId === null ? [] : [fullscreenAppRowId]),
755
...new Set(
@@ -1354,6 +1360,10 @@ function TimelineHistoryControl(props: MessagesTimelineHistoryControls) {
1360
);
1361
}
1362
1363
+function isMessageRow(row: MessagesTimelineRow) {
1364
+ return row.kind === "message" && row.message.role !== "system";
1365
+}
1366
+
1367
function keyExtractor(item: MessagesTimelineRow) {
1368
return item.id;
1369
}
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+11
-4
@@ -168,6 +168,7 @@ function AutomationMessageRow({ row }: { row: Extract<TimelineRow, { kind: "mess
168
expanded && "w-full",
169
)}
170
>
171
+ <MessageAuthorHeading>Automation</MessageAuthorHeading>
172
<FoldedMessageHeader
173
icon={CalendarClockIcon}
174
label="Automation"
@@ -311,6 +312,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
312
? { environmentId: ctx.activeThreadEnvironmentId, threadId: senderThreadId }
313
: null,
314
);
315
+ const senderLabel = senderShell?.title.trim() || "Agent";
316
const resolvedContext = resolveUserMessageContext(
317
userMessage.attribution === "guest" ? { ...row.message, text: userMessage.text } : row.message,
318
);
@@ -457,10 +459,18 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
459
folded && expanded && "w-full",
460
)}
461
>
462
+ {/* Outside the fold so a collapsed message still has a heading to navigate to. */}
463
+ <MessageAuthorHeading>
464
+ {folded
465
+ ? senderLabel
466
+ : userMessage.guestName === undefined
467
+ ? "You"
468
+ : `${userMessage.guestName} (guest)`}
469
+ </MessageAuthorHeading>
470
{folded ? (
471
<FoldedMessageHeader
472
icon={MessagesSquareIcon}
463
- label={senderShell?.title.trim() || "Agent"}
473
+ label={senderLabel}
474
summary={foldSummary}
475
expanded={expanded}
476
onToggle={() => setExpanded((value) => !value)}
@@ -476,9 +486,6 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
486
folded && !ctx.findActive && "max-h-96 overflow-auto",
487
)}
488
>
479
- <MessageAuthorHeading>
480
- {userMessage.guestName === undefined ? "You" : `${userMessage.guestName} (guest)`}
481
- </MessageAuthorHeading>
489
{(regularImages.length > 0 || userVideos.length > 0) && (
490
<div className="mb-2 grid max-w-[210px] grid-cols-2 gap-2">
491
{regularImages.map((image) => (
patches/@legendapp__list@3.3.5.patch
+364
-16
@@ -1619,10 +1619,102 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..d7cbe1cb43449cc29822b2646deabbdd
1619
}
1620
}
1621
diff --git a/react.js b/react.js
1622
-index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c0430059a 100644
1622
+index 914d2dafaafa001c9ab6791a0a0581659295e333..8c320b0dfb3ea60ef145274b37b1297b7dee26dc 100644
1623
--- a/react.js
1624
+++ b/react.js
1625
-@@ -4702,7 +4702,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
1625
+@@ -1908,6 +1908,10 @@ function updateScroll(ctx, newScroll, forceUpdate, options) {
1626
+ state.scrollTime = currentTime;
1627
+ const scrollDelta = Math.abs(newScroll - prevScroll);
1628
+ const isUserScrollEvent = !!(options == null ? void 0 : options.fromNativeScrollEvent) && scrollDelta > 0.1 && !adjustChanged && scrollingTo === void 0 && !state.pendingNativeMVCPAdjust;
1629
++ if (isUserScrollEvent) {
1630
++ state.userScrollPrevTime = state.userScrollTime;
1631
++ state.userScrollTime = currentTime;
1632
++ }
1633
+ const allowedEdge = isUserScrollEvent ? beginReachedEdgeUserScroll(ctx, newScroll - prevScroll) : void 0;
1634
+ const didResolvePendingNativeMVCPAdjust = resolvePendingNativeMVCPAdjust(ctx, newScroll);
1635
+ const scrollLength = state.scrollLength;
1636
+@@ -3257,6 +3261,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1637
+ const itemKey = (_a3 = state.idCache[itemIndex]) != null ? _a3 : getId(state, itemIndex);
1638
+ const updateLayout = (_b = options == null ? void 0 : options.updateLayout) != null ? _b : true;
1639
+ let didChangePosition = false;
1640
++ let didChangeIndex = false;
1641
+ let didRefreshData = false;
1642
+ if (updateLayout) {
1643
+ const positionValue = positions[itemIndex];
1644
+@@ -3286,6 +3291,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1645
+ const prevIndex = peek$(ctx, `containerItemIndex${containerIndex}`);
1646
+ if (prevIndex !== itemIndex) {
1647
+ set$(ctx, `containerItemIndex${containerIndex}`, itemIndex);
1648
++ didChangeIndex = true;
1649
+ }
1650
+ const prevData = peek$(ctx, `containerItemData${containerIndex}`);
1651
+ const updateData = () => {
1652
+@@ -3324,7 +3330,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1653
+ }
1654
+ }
1655
+ }
1656
+- return { didChangePosition, didRefreshData };
1657
++ return { didChangeIndex, didChangePosition, didRefreshData };
1658
+ }
1659
+
1660
+ // src/core/prepareColumnStartState.ts
1661
+@@ -3542,7 +3548,11 @@ function updateItemPositions(ctx, dataChanged, {
1662
+ }
1663
+ if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) {
1664
+ const itemsPerRow = hasColumns ? numColumns : 1;
1665
+- breakAt = i + itemsPerRow + 10;
1666
++ // alwaysRender rows stay mounted outside the visible window, so keep their
1667
++ // positions current instead of leaving them where they were last laid out.
1668
++ const pinnedIndices = state.props.alwaysRenderIndicesArr;
1669
++ const lastPinnedIndex = pinnedIndices && pinnedIndices.length > 0 ? pinnedIndices[pinnedIndices.length - 1] : -1;
1670
++ breakAt = Math.max(i + itemsPerRow + 10, lastPinnedIndex);
1671
+ }
1672
+ const id = (_e = idCache[i]) != null ? _e : getId(state, i);
1673
+ let span = 1;
1674
+@@ -4243,6 +4253,7 @@ function calculateItemsInView(ctx, params = {}) {
1675
+ }
1676
+ let totalSize = getContentSize(ctx);
1677
+ let changedContainerIds;
1678
++ let didChangeContainerOrder = false;
1679
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "alignItemsAtEndPadding") + peek$(ctx, "headerSize");
1680
+ const numColumns = peek$(ctx, "numColumns");
1681
+ const speed = (_b = params.scrollVelocity) != null ? _b : getScrollVelocity(state);
1682
+@@ -4545,6 +4556,9 @@ function calculateItemsInView(ctx, params = {}) {
1683
+ const containerIndex = allocation.containerIndex;
1684
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
1685
+ const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1686
++ if (oldKey !== id || peek$(ctx, `containerItemIndex${containerIndex}`) !== i) {
1687
++ didChangeContainerOrder = true;
1688
++ }
1689
+ if (oldKey && oldKey !== id) {
1690
+ containerItemKeys.delete(oldKey);
1691
+ }
1692
+@@ -4629,10 +4643,12 @@ function calculateItemsInView(ctx, params = {}) {
1693
+ } else {
1694
+ const itemIndex = indexByKey.get(itemKey);
1695
+ if (itemIndex !== void 0) {
1696
+- didChangePositions = syncMountedContainer(ctx, i, itemIndex, {
1697
++ const synced = syncMountedContainer(ctx, i, itemIndex, {
1698
+ scrollAdjustPending,
1699
+ updateLayout: true
1700
+- }).didChangePosition || didChangePositions;
1701
++ });
1702
++ didChangePositions = synced.didChangePosition || didChangePositions;
1703
++ didChangeContainerOrder = synced.didChangeIndex || didChangeContainerOrder;
1704
+ }
1705
+ }
1706
+ }
1707
+@@ -4642,6 +4658,9 @@ function calculateItemsInView(ctx, params = {}) {
1708
+ if (didChangePositions) {
1709
+ set$(ctx, "lastPositionUpdate", Date.now());
1710
+ }
1711
++ if (didChangeContainerOrder) {
1712
++ set$(ctx, "containerOrderUpdate", (peek$(ctx, "containerOrderUpdate") || 0) + 1);
1713
++ }
1714
+ if (suppressInitialScrollSideEffects) {
1715
+ evaluateBootstrapInitialScroll(ctx);
1716
+ return;
1717
+@@ -4702,7 +4721,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
1718
contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap);
1719
contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props);
1720
isReady = !hasUnknownTailSize;
@@ -1632,7 +1724,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1724
} else if (anchorIndex >= 0) {
1725
isReady = false;
1726
}
1635
-@@ -4722,6 +4723,12 @@ function maybeUpdateAnchoredEndSpace(ctx) {
1727
+@@ -4722,6 +4742,12 @@ function maybeUpdateAnchoredEndSpace(ctx) {
1728
updateScroll(ctx, state.scroll, true, { markHasScrolled: false });
1729
}
1730
(_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize });
@@ -1645,7 +1737,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1737
}
1738
return nextSize;
1739
}
1648
-@@ -4956,7 +4963,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) {
1740
+@@ -4956,7 +4982,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) {
1741
const itemKey = peek$(ctx, `containerItemKey${containerId}`);
1742
const element = viewRef == null ? void 0 : viewRef.current;
1743
if (itemKey !== void 0 && element) {
@@ -1655,7 +1747,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1747
setContainerLayoutBaseline(element, rect);
1748
measurements.push({
1749
containerId,
1658
-@@ -4978,12 +4986,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
1750
+@@ -4978,12 +5005,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
1751
}) {
1752
const ctx = useStateContext();
1753
const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]);
@@ -1687,7 +1779,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1779
}
1780
}, [ctx, containerLayoutEpoch]);
1781
return children;
1690
-@@ -5651,6 +5673,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1782
+@@ -5651,6 +5692,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1783
});
1784
1785
// src/utils/reordering.ts
@@ -1706,7 +1798,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1798
function sortDOMElements(container, indexByElement) {
1799
const elements = Array.from(container.children);
1800
if (elements.length <= 1) return elements;
1709
-@@ -5690,9 +5724,9 @@ function sortDOMElements(container, indexByElement) {
1801
+@@ -5690,9 +5743,9 @@ function sortDOMElements(container, indexByElement) {
1802
}
1803
}
1804
if (nextStableElement) {
@@ -1718,7 +1810,89 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1810
}
1811
}
1812
}
1721
-@@ -6446,8 +6480,8 @@ function ScrollAdjust() {
1813
+@@ -5734,37 +5787,55 @@ function findLIS(arr) {
1814
+ }
1815
+
1816
+ // src/hooks/useDOMOrder.ts
1817
++var DOM_ORDER_SETTLE_MS = 150;
1818
++function isUserScrolling(state) {
1819
++ const { userScrollPrevTime, userScrollTime } = state;
1820
++ return userScrollTime !== void 0 && userScrollPrevTime !== void 0 && userScrollTime - userScrollPrevTime < DOM_ORDER_SETTLE_MS && Date.now() - userScrollTime < DOM_ORDER_SETTLE_MS;
1821
++}
1822
+ function useDOMOrder(ref) {
1823
+ const ctx = useStateContext();
1824
+- const debounceRef = React3.useRef(void 0);
1825
+- React3.useEffect(() => {
1826
+- const unsubscribe = listen$(ctx, "lastPositionUpdate", () => {
1827
+- if (debounceRef.current !== void 0) {
1828
+- clearTimeout(debounceRef.current);
1829
+- }
1830
+- debounceRef.current = setTimeout(() => {
1831
+- const parent = ref.current;
1832
+- if (parent) {
1833
+- const indexByElement = /* @__PURE__ */ new Map();
1834
+- for (const [containerId, viewRef] of ctx.viewRefs) {
1835
+- const element = viewRef.current;
1836
+- const index = peek$(ctx, `containerItemIndex${containerId}`);
1837
+- if (element && index !== void 0) {
1838
+- indexByElement.set(element, index);
1839
+- }
1840
+- }
1841
+- sortDOMElements(parent, indexByElement);
1842
++ const [containerOrderUpdate] = useArr$(["containerOrderUpdate"]);
1843
++ const settleRef = React3.useRef(void 0);
1844
++ React3.useLayoutEffect(() => {
1845
++ const sort = () => {
1846
++ settleRef.current = void 0;
1847
++ const parent = ref.current;
1848
++ if (!parent) {
1849
++ return;
1850
++ }
1851
++ const indexByElement = /* @__PURE__ */ new Map();
1852
++ for (const [containerId, viewRef] of ctx.viewRefs) {
1853
++ const element = viewRef.current;
1854
++ const index = peek$(ctx, `containerItemIndex${containerId}`);
1855
++ if (element && index !== void 0) {
1856
++ indexByElement.set(element, index);
1857
+ }
1858
+- debounceRef.current = void 0;
1859
+- }, 500);
1860
+- });
1861
+- return () => {
1862
+- unsubscribe();
1863
+- if (debounceRef.current !== void 0) {
1864
+- clearTimeout(debounceRef.current);
1865
+ }
1866
++ sortDOMElements(parent, indexByElement);
1867
+ };
1868
+- }, [ctx]);
1869
++ if (settleRef.current !== void 0) {
1870
++ clearTimeout(settleRef.current);
1871
++ }
1872
++ // Before paint: NVDA's browse mode keeps the first DOM order it reads. Each move
1873
++ // lays its row out again, so during a continuous scroll, sort once it settles.
1874
++ if (!isUserScrolling(ctx.state)) {
1875
++ sort();
1876
++ return;
1877
++ }
1878
++ const settle = () => {
1879
++ if (isUserScrolling(ctx.state)) {
1880
++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS);
1881
++ } else {
1882
++ sort();
1883
++ }
1884
++ };
1885
++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS);
1886
++ }, [ctx, containerOrderUpdate]);
1887
++ React3.useEffect(() => () => {
1888
++ if (settleRef.current !== void 0) {
1889
++ clearTimeout(settleRef.current);
1890
++ }
1891
++ }, []);
1892
+ }
1893
+ function useFreshDataTransitionVisibility(readyToRender, transitionEpoch) {
1894
+ const [completedTransitionEpoch, setCompletedTransitionEpoch] = React3.useState(transitionEpoch);
1895
+@@ -6446,8 +6517,8 @@ function ScrollAdjust() {
1896
window.getComputedStyle(contentNode)[axis.paddingEndProp]
1897
);
1898
const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`;
@@ -1729,10 +1903,102 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c
1903
scrollBy();
1904
if (resetPaddingRafRef.current !== void 0) {
1905
diff --git a/react.mjs b/react.mjs
1732
-index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e2e456cfc 100644
1906
+index 95465f2ab89ce41a10553f58af83618f7310e83c..252a9d5b23e271c089d30c357a78dff754f1c899 100644
1907
--- a/react.mjs
1908
+++ b/react.mjs
1735
-@@ -4681,7 +4681,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
1909
+@@ -1887,6 +1887,10 @@ function updateScroll(ctx, newScroll, forceUpdate, options) {
1910
+ state.scrollTime = currentTime;
1911
+ const scrollDelta = Math.abs(newScroll - prevScroll);
1912
+ const isUserScrollEvent = !!(options == null ? void 0 : options.fromNativeScrollEvent) && scrollDelta > 0.1 && !adjustChanged && scrollingTo === void 0 && !state.pendingNativeMVCPAdjust;
1913
++ if (isUserScrollEvent) {
1914
++ state.userScrollPrevTime = state.userScrollTime;
1915
++ state.userScrollTime = currentTime;
1916
++ }
1917
+ const allowedEdge = isUserScrollEvent ? beginReachedEdgeUserScroll(ctx, newScroll - prevScroll) : void 0;
1918
+ const didResolvePendingNativeMVCPAdjust = resolvePendingNativeMVCPAdjust(ctx, newScroll);
1919
+ const scrollLength = state.scrollLength;
1920
+@@ -3236,6 +3240,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1921
+ const itemKey = (_a3 = state.idCache[itemIndex]) != null ? _a3 : getId(state, itemIndex);
1922
+ const updateLayout = (_b = options == null ? void 0 : options.updateLayout) != null ? _b : true;
1923
+ let didChangePosition = false;
1924
++ let didChangeIndex = false;
1925
+ let didRefreshData = false;
1926
+ if (updateLayout) {
1927
+ const positionValue = positions[itemIndex];
1928
+@@ -3265,6 +3270,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1929
+ const prevIndex = peek$(ctx, `containerItemIndex${containerIndex}`);
1930
+ if (prevIndex !== itemIndex) {
1931
+ set$(ctx, `containerItemIndex${containerIndex}`, itemIndex);
1932
++ didChangeIndex = true;
1933
+ }
1934
+ const prevData = peek$(ctx, `containerItemData${containerIndex}`);
1935
+ const updateData = () => {
1936
+@@ -3303,7 +3309,7 @@ function syncMountedContainer(ctx, containerIndex, itemIndex, options) {
1937
+ }
1938
+ }
1939
+ }
1940
+- return { didChangePosition, didRefreshData };
1941
++ return { didChangeIndex, didChangePosition, didRefreshData };
1942
+ }
1943
+
1944
+ // src/core/prepareColumnStartState.ts
1945
+@@ -3521,7 +3527,11 @@ function updateItemPositions(ctx, dataChanged, {
1946
+ }
1947
+ if (shouldOptimize && breakAt === void 0 && !scrollingTo && !dataChanged && currentRowTop > maxVisibleArea) {
1948
+ const itemsPerRow = hasColumns ? numColumns : 1;
1949
+- breakAt = i + itemsPerRow + 10;
1950
++ // alwaysRender rows stay mounted outside the visible window, so keep their
1951
++ // positions current instead of leaving them where they were last laid out.
1952
++ const pinnedIndices = state.props.alwaysRenderIndicesArr;
1953
++ const lastPinnedIndex = pinnedIndices && pinnedIndices.length > 0 ? pinnedIndices[pinnedIndices.length - 1] : -1;
1954
++ breakAt = Math.max(i + itemsPerRow + 10, lastPinnedIndex);
1955
+ }
1956
+ const id = (_e = idCache[i]) != null ? _e : getId(state, i);
1957
+ let span = 1;
1958
+@@ -4222,6 +4232,7 @@ function calculateItemsInView(ctx, params = {}) {
1959
+ }
1960
+ let totalSize = getContentSize(ctx);
1961
+ let changedContainerIds;
1962
++ let didChangeContainerOrder = false;
1963
+ const topPad = peek$(ctx, "stylePaddingTop") + peek$(ctx, "alignItemsAtEndPadding") + peek$(ctx, "headerSize");
1964
+ const numColumns = peek$(ctx, "numColumns");
1965
+ const speed = (_b = params.scrollVelocity) != null ? _b : getScrollVelocity(state);
1966
+@@ -4524,6 +4535,9 @@ function calculateItemsInView(ctx, params = {}) {
1967
+ const containerIndex = allocation.containerIndex;
1968
+ const id = (_o = idCache[i]) != null ? _o : getId(state, i);
1969
+ const oldKey = peek$(ctx, `containerItemKey${containerIndex}`);
1970
++ if (oldKey !== id || peek$(ctx, `containerItemIndex${containerIndex}`) !== i) {
1971
++ didChangeContainerOrder = true;
1972
++ }
1973
+ if (oldKey && oldKey !== id) {
1974
+ containerItemKeys.delete(oldKey);
1975
+ }
1976
+@@ -4608,10 +4622,12 @@ function calculateItemsInView(ctx, params = {}) {
1977
+ } else {
1978
+ const itemIndex = indexByKey.get(itemKey);
1979
+ if (itemIndex !== void 0) {
1980
+- didChangePositions = syncMountedContainer(ctx, i, itemIndex, {
1981
++ const synced = syncMountedContainer(ctx, i, itemIndex, {
1982
+ scrollAdjustPending,
1983
+ updateLayout: true
1984
+- }).didChangePosition || didChangePositions;
1985
++ });
1986
++ didChangePositions = synced.didChangePosition || didChangePositions;
1987
++ didChangeContainerOrder = synced.didChangeIndex || didChangeContainerOrder;
1988
+ }
1989
+ }
1990
+ }
1991
+@@ -4621,6 +4637,9 @@ function calculateItemsInView(ctx, params = {}) {
1992
+ if (didChangePositions) {
1993
+ set$(ctx, "lastPositionUpdate", Date.now());
1994
+ }
1995
++ if (didChangeContainerOrder) {
1996
++ set$(ctx, "containerOrderUpdate", (peek$(ctx, "containerOrderUpdate") || 0) + 1);
1997
++ }
1998
+ if (suppressInitialScrollSideEffects) {
1999
+ evaluateBootstrapInitialScroll(ctx);
2000
+ return;
2001
+@@ -4681,7 +4700,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
2002
contentBelowAnchor = Math.max(0, contentBelowAnchor - ctx.scrollAxisGap);
2003
contentBelowAnchor += (ctx.values.get("footerSize") || 0) + getStylePaddingEnd(state.props);
2004
isReady = !hasUnknownTailSize;
@@ -1742,7 +2008,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2008
} else if (anchorIndex >= 0) {
2009
isReady = false;
2010
}
1745
-@@ -4701,6 +4702,12 @@ function maybeUpdateAnchoredEndSpace(ctx) {
2011
+@@ -4701,6 +4721,12 @@ function maybeUpdateAnchoredEndSpace(ctx) {
2012
updateScroll(ctx, state.scroll, true, { markHasScrolled: false });
2013
}
2014
(_b = anchoredEndSpace == null ? void 0 : anchoredEndSpace.onReady) == null ? void 0 : _b.call(anchoredEndSpace, { anchorIndex: nextAnchorIndex, anchorKey: nextAnchorKey, size: nextSize });
@@ -1755,7 +2021,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2021
}
2022
return nextSize;
2023
}
1758
-@@ -4935,7 +4942,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) {
2024
+@@ -4935,7 +4961,8 @@ function measureContainersInLayoutEffect(ctx, targetContainerIds = null) {
2025
const itemKey = peek$(ctx, `containerItemKey${containerId}`);
2026
const element = viewRef == null ? void 0 : viewRef.current;
2027
if (itemKey !== void 0 && element) {
@@ -1765,7 +2031,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2031
setContainerLayoutBaseline(element, rect);
2032
measurements.push({
2033
containerId,
1768
-@@ -4957,12 +4965,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
2034
+@@ -4957,12 +4984,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
2035
}) {
2036
const ctx = useStateContext();
2037
const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]);
@@ -1797,7 +2063,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2063
}
2064
}, [ctx, containerLayoutEpoch]);
2065
return children;
1800
-@@ -5630,6 +5652,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
2066
+@@ -5630,6 +5671,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
2067
});
2068
2069
// src/utils/reordering.ts
@@ -1816,7 +2082,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2082
function sortDOMElements(container, indexByElement) {
2083
const elements = Array.from(container.children);
2084
if (elements.length <= 1) return elements;
1819
-@@ -5669,9 +5703,9 @@ function sortDOMElements(container, indexByElement) {
2085
+@@ -5669,9 +5722,9 @@ function sortDOMElements(container, indexByElement) {
2086
}
2087
}
2088
if (nextStableElement) {
@@ -1828,7 +2094,89 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e
2094
}
2095
}
2096
}
1831
-@@ -6425,8 +6459,8 @@ function ScrollAdjust() {
2097
+@@ -5713,37 +5766,55 @@ function findLIS(arr) {
2098
+ }
2099
+
2100
+ // src/hooks/useDOMOrder.ts
2101
++var DOM_ORDER_SETTLE_MS = 150;
2102
++function isUserScrolling(state) {
2103
++ const { userScrollPrevTime, userScrollTime } = state;
2104
++ return userScrollTime !== void 0 && userScrollPrevTime !== void 0 && userScrollTime - userScrollPrevTime < DOM_ORDER_SETTLE_MS && Date.now() - userScrollTime < DOM_ORDER_SETTLE_MS;
2105
++}
2106
+ function useDOMOrder(ref) {
2107
+ const ctx = useStateContext();
2108
+- const debounceRef = useRef(void 0);
2109
+- useEffect(() => {
2110
+- const unsubscribe = listen$(ctx, "lastPositionUpdate", () => {
2111
+- if (debounceRef.current !== void 0) {
2112
+- clearTimeout(debounceRef.current);
2113
+- }
2114
+- debounceRef.current = setTimeout(() => {
2115
+- const parent = ref.current;
2116
+- if (parent) {
2117
+- const indexByElement = /* @__PURE__ */ new Map();
2118
+- for (const [containerId, viewRef] of ctx.viewRefs) {
2119
+- const element = viewRef.current;
2120
+- const index = peek$(ctx, `containerItemIndex${containerId}`);
2121
+- if (element && index !== void 0) {
2122
+- indexByElement.set(element, index);
2123
+- }
2124
+- }
2125
+- sortDOMElements(parent, indexByElement);
2126
++ const [containerOrderUpdate] = useArr$(["containerOrderUpdate"]);
2127
++ const settleRef = useRef(void 0);
2128
++ useLayoutEffect(() => {
2129
++ const sort = () => {
2130
++ settleRef.current = void 0;
2131
++ const parent = ref.current;
2132
++ if (!parent) {
2133
++ return;
2134
++ }
2135
++ const indexByElement = /* @__PURE__ */ new Map();
2136
++ for (const [containerId, viewRef] of ctx.viewRefs) {
2137
++ const element = viewRef.current;
2138
++ const index = peek$(ctx, `containerItemIndex${containerId}`);
2139
++ if (element && index !== void 0) {
2140
++ indexByElement.set(element, index);
2141
+ }
2142
+- debounceRef.current = void 0;
2143
+- }, 500);
2144
+- });
2145
+- return () => {
2146
+- unsubscribe();
2147
+- if (debounceRef.current !== void 0) {
2148
+- clearTimeout(debounceRef.current);
2149
+ }
2150
++ sortDOMElements(parent, indexByElement);
2151
+ };
2152
+- }, [ctx]);
2153
++ if (settleRef.current !== void 0) {
2154
++ clearTimeout(settleRef.current);
2155
++ }
2156
++ // Before paint: NVDA's browse mode keeps the first DOM order it reads. Each move
2157
++ // lays its row out again, so during a continuous scroll, sort once it settles.
2158
++ if (!isUserScrolling(ctx.state)) {
2159
++ sort();
2160
++ return;
2161
++ }
2162
++ const settle = () => {
2163
++ if (isUserScrolling(ctx.state)) {
2164
++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS);
2165
++ } else {
2166
++ sort();
2167
++ }
2168
++ };
2169
++ settleRef.current = setTimeout(settle, DOM_ORDER_SETTLE_MS);
2170
++ }, [ctx, containerOrderUpdate]);
2171
++ useEffect(() => () => {
2172
++ if (settleRef.current !== void 0) {
2173
++ clearTimeout(settleRef.current);
2174
++ }
2175
++ }, []);
2176
+ }
2177
+ function useFreshDataTransitionVisibility(readyToRender, transitionEpoch) {
2178
+ const [completedTransitionEpoch, setCompletedTransitionEpoch] = useState(transitionEpoch);
2179
+@@ -6425,8 +6496,8 @@ function ScrollAdjust() {
2180
window.getComputedStyle(contentNode)[axis.paddingEndProp]
2181
);
2182
const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`;
pnpm-lock.yaml
+4
-4
@@ -352,7 +352,7 @@ patchedDependencies:
352
'@expo/metro-config@58.0.14': 90fa980e8b6480631fb2fbb04559834e3c612db40c550cd828f11be297d8d760
353
'@expo/ui@58.0.20': 5a26480373850c1a7943919aa21f904151b335a0cb01042109e0746def37923e
354
'@ff-labs/fff-node@0.11.0': cc71fcec015f4d39bc96ae2e2bf6b0ca678124c722c66a7841efce9d34b5983c
355
- '@legendapp/list@3.3.5': 011a862a7116ec5b5f4bba17d37bc58c9b5a8f64a6a9f527345f316ce9c96e63
355
+ '@legendapp/list@3.3.5': 6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896
356
'@muse-code/sdk@1.4.6': 7b495b607fc5d76b444c7c4d58821e839726a30e6f3c53564f0d59f2d5b42101
357
'@pierre/diffs@1.6.1': 4645364ddf113e48e8827f3b4966b3b1ff745317011e5a3d904e2d8672dee7dc
358
'@react-native-ai/apple@0.12.0': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
@@ -530,7 +530,7 @@ importers:
530
version: 58.0.20(patch_hash=5a26480373850c1a7943919aa21f904151b335a0cb01042109e0746def37923e)(@babel/core@7.29.7(supports-color@8.1.1))(expo@58.0.14)(react-dom@19.3.0(react@19.3.0))(react-native-worklets@0.13.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)(supports-color@8.1.1))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
531
'@legendapp/list':
532
specifier: 3.3.5
533
- version: 3.3.5(patch_hash=011a862a7116ec5b5f4bba17d37bc58c9b5a8f64a6a9f527345f316ce9c96e63)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
533
+ version: 3.3.5(patch_hash=6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
534
'@material/material-color-utilities':
535
specifier: 0.3.0
536
version: 0.3.0
@@ -1039,7 +1039,7 @@ importers:
1039
version: 0.9.0
1040
'@legendapp/list':
1041
specifier: 3.3.5
1042
- version: 3.3.5(patch_hash=011a862a7116ec5b5f4bba17d37bc58c9b5a8f64a6a9f527345f316ce9c96e63)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
1042
+ version: 3.3.5(patch_hash=6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)
1043
'@noble/hashes':
1044
specifier: 'catalog:'
1045
version: 1.8.0
@@ -14766,7 +14766,7 @@ snapshots:
14766
dependencies:
14767
jsbi: 4.3.2
14768
14769
- '@legendapp/list@3.3.5(patch_hash=011a862a7116ec5b5f4bba17d37bc58c9b5a8f64a6a9f527345f316ce9c96e63)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)':
14769
+ '@legendapp/list@3.3.5(patch_hash=6cbdacd8c380d9a5afb9f73d4198dc2cc44be6ef28a955b1183c781469307896)(react-dom@19.3.0(react@19.3.0))(react-native@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(@react-native/metro-config@0.88.0(@babel/core@7.29.7(supports-color@8.1.1))(bufferutil@4.1.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(@types/react@19.3.0)(bufferutil@4.1.0)(react@19.3.0)(supports-color@8.1.1)(utf-8-validate@6.0.6))(react@19.3.0)':
14770
dependencies:
14771
react: 19.3.0
14772
use-sync-external-store: 1.6.0(react@19.3.0)