The best way to control Claude Code, Codex and more from any computer or phone
fix(web): cap list layout passes to prevent React error 185 (#23315)
Yash Singh committed
Oct 21, 2026 at 22:28 UTC
05b697f6a2012497ae790425e197fbd1fcef7de7
3 files changed
+124
-15
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+46
-1
@@ -1,6 +1,6 @@
1
import { EnvironmentId, MessageId, RunId, ScheduledTaskId } from "@t3tools/contracts";
2
import type { LegendListRef } from "@legendapp/list/react";
3
-import { createRef, type ComponentProps, type ReactElement } from "react";
3
+import { createRef, Profiler, type ComponentProps, type ReactElement } from "react";
4
import { describe, expect, it, vi } from "vite-plus/test";
5
6
import "~/index.css";
@@ -129,6 +129,51 @@ const TASK_ID = ScheduledTaskId.make("task-1");
129
const AUTOMATION_PROMPT = "Triage the inbox\n\nLabel every new issue and close duplicates.";
130
131
describe("MessagesTimeline messages", () => {
132
+ it("settles when equally long messages have very different rendered heights", async () => {
133
+ const props = baseProps();
134
+ const tall = message("a\n\n".repeat(6000), { role: "assistant" }, "tall");
135
+ const earlier = Array.from({ length: 80 }, (_, index) =>
136
+ message(
137
+ `<details><summary>Reply ${index}</summary>${"compact ".repeat(2250)}</details>`,
138
+ { role: "assistant" },
139
+ `earlier-${index}`,
140
+ ),
141
+ );
142
+ let nestedCommits = 0;
143
+ let maxNestedCommits = 0;
144
+ const onRender = (_id: string, phase: string) => {
145
+ nestedCommits = phase === "nested-update" ? nestedCommits + 1 : 0;
146
+ maxNestedCommits = Math.max(maxNestedCommits, nestedCommits);
147
+ };
148
+ const timeline = (entries: Entry[]) => (
149
+ <Profiler id="timeline" onRender={onRender}>
150
+ <MessagesTimeline {...props} timelineEntries={entries} />
151
+ </Profiler>
152
+ );
153
+ await using screen = await renderElement(timeline([tall]));
154
+ await vi.waitFor(() =>
155
+ expect(props.listRef.current?.getState().sizeAtIndex(0)).toBeGreaterThan(100_000),
156
+ );
157
+ const viewport = props.listRef.current!.getScrollableNode()!;
158
+ await act(() => {
159
+ viewport.scrollTop = 0;
160
+ viewport.dispatchEvent(new Event("scroll"));
161
+ });
162
+ await screen.rerender(timeline([...earlier, tall]));
163
+ await act(() => {
164
+ void props.listRef.current!.scrollToIndex({ index: 0, animated: false });
165
+ });
166
+ await vi.waitFor(async () => {
167
+ await act(() => {
168
+ viewport.scrollTop = 0;
169
+ viewport.dispatchEvent(new Event("scroll"));
170
+ });
171
+ expect(screen.text().includes("Reply 0")).toBe(true);
172
+ expect(props.listRef.current!.getState().sizeAtIndex(0)).toBeGreaterThan(0);
173
+ });
174
+ expect(maxNestedCommits).toBeLessThan(20);
175
+ });
176
+
177
it("preserves XML-like tags and comparisons in user messages as text", async () => {
178
const source = [
179
'Without reading a file, do you have <global-agent-instructions scope="workspace">',
patches/@legendapp__list@3.3.5.patch
+74
-10
@@ -269,7 +269,7 @@ index ce1fe00001c9e5aee6c6ea8bb2d4757d4586d002..ca6e596aa53327a097a388ffd545a4c6
269
* Number of columns to render items in.
270
* @default 1
271
diff --git a/react-native.js b/react-native.js
272
-index b3c5a306b293f797a8b338adfca3060c0f6db22b..3c67a536d850d8c508336cf0f10c0c898ea67f12 100644
272
+index b3c5a306b293f797a8b338adfca3060c0f6db22b..d7f59b63cd4982dfc9c347732caa77e0974864df 100644
273
--- a/react-native.js
274
+++ b/react-native.js
275
@@ -717,6 +717,15 @@ function hasActiveInitialScroll(state) {
@@ -909,7 +909,7 @@ index b3c5a306b293f797a8b338adfca3060c0f6db22b..3c67a536d850d8c508336cf0f10c0c89
909
recycleItems,
910
refreshControl: refreshControlElement ? stylePaddingTopState > 0 ? React2__namespace.cloneElement(refreshControlElement, {
911
diff --git a/react-native.mjs b/react-native.mjs
912
-index 40e87cda8c9bc79a889e5542f29af429a24b24d4..c1b68df0f53d566c98a4820b39079396a09f1208 100644
912
+index 40e87cda8c9bc79a889e5542f29af429a24b24d4..c2ca39bab6ea1ebaaed25190a01e8cf2e395ece9 100644
913
--- a/react-native.mjs
914
+++ b/react-native.mjs
915
@@ -696,6 +696,15 @@ function hasActiveInitialScroll(state) {
@@ -1619,7 +1619,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..d7cbe1cb43449cc29822b2646deabbdd
1619
}
1620
}
1621
diff --git a/react.js b/react.js
1622
-index 914d2dafaafa001c9ab6791a0a0581659295e333..86dbd9a5c7345577e4a8a435041ecb68257ae9f1 100644
1622
+index 914d2dafaafa001c9ab6791a0a0581659295e333..199aae77b3620b7c4bb2ecd96b82978c0430059a 100644
1623
--- a/react.js
1624
+++ b/react.js
1625
@@ -4702,7 +4702,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
@@ -1655,7 +1655,39 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..86dbd9a5c7345577e4a8a435041ecb68
1655
setContainerLayoutBaseline(element, rect);
1656
measurements.push({
1657
containerId,
1658
-@@ -5651,6 +5659,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1658
+@@ -4978,12 +4986,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
1659
+ }) {
1660
+ const ctx = useStateContext();
1661
+ const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]);
1662
++ const layoutPasses = React3__namespace.useRef(0);
1663
+ React3__namespace.useLayoutEffect(() => {
1664
+- {
1665
+- const targetContainerIds = getContainerLayoutEffectScope(ctx);
1666
+- if (targetContainerIds !== void 0) {
1667
+- measureContainersInLayoutEffect(ctx, targetContainerIds);
1668
+- }
1669
++ const targetContainerIds = getContainerLayoutEffectScope(ctx);
1670
++ if (targetContainerIds === void 0) return;
1671
++ if (layoutPasses.current === 0) {
1672
++ queueMicrotask(() => { layoutPasses.current = 0; });
1673
++ }
1674
++ // Correcting large estimates can mount one row per commit. Bound the
1675
++ // synchronous chain below React's nested-update limit, then keep measuring
1676
++ // the latest pending rows on the next frame. Idle lists schedule no work.
1677
++ if (layoutPasses.current++ < 8) {
1678
++ measureContainersInLayoutEffect(ctx, targetContainerIds);
1679
++ } else {
1680
++ ctx.pendingContainerIds = targetContainerIds;
1681
++ ctx.state.scheduledWork.frame(() => {
1682
++ const pendingIds = getContainerLayoutEffectScope(ctx);
1683
++ if (pendingIds !== void 0) {
1684
++ measureContainersInLayoutEffect(ctx, pendingIds);
1685
++ }
1686
++ }, "containerLayout");
1687
+ }
1688
+ }, [ctx, containerLayoutEpoch]);
1689
+ return children;
1690
+@@ -5651,6 +5673,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1691
});
1692
1693
// src/utils/reordering.ts
@@ -1674,7 +1706,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..86dbd9a5c7345577e4a8a435041ecb68
1706
function sortDOMElements(container, indexByElement) {
1707
const elements = Array.from(container.children);
1708
if (elements.length <= 1) return elements;
1677
-@@ -5690,9 +5710,9 @@ function sortDOMElements(container, indexByElement) {
1709
+@@ -5690,9 +5724,9 @@ function sortDOMElements(container, indexByElement) {
1710
}
1711
}
1712
if (nextStableElement) {
@@ -1686,7 +1718,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..86dbd9a5c7345577e4a8a435041ecb68
1718
}
1719
}
1720
}
1689
-@@ -6446,8 +6466,8 @@ function ScrollAdjust() {
1721
+@@ -6446,8 +6480,8 @@ function ScrollAdjust() {
1722
window.getComputedStyle(contentNode)[axis.paddingEndProp]
1723
);
1724
const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`;
@@ -1697,7 +1729,7 @@ index 914d2dafaafa001c9ab6791a0a0581659295e333..86dbd9a5c7345577e4a8a435041ecb68
1729
scrollBy();
1730
if (resetPaddingRafRef.current !== void 0) {
1731
diff --git a/react.mjs b/react.mjs
1700
-index 95465f2ab89ce41a10553f58af83618f7310e83c..cff49dc5c769cab264b8527a268851295c44aa33 100644
1732
+index 95465f2ab89ce41a10553f58af83618f7310e83c..a123bd3e9df510100d44dfae1f59b87e2e456cfc 100644
1733
--- a/react.mjs
1734
+++ b/react.mjs
1735
@@ -4681,7 +4681,8 @@ function maybeUpdateAnchoredEndSpace(ctx) {
@@ -1733,7 +1765,39 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..cff49dc5c769cab264b8527a26885129
1765
setContainerLayoutBaseline(element, rect);
1766
measurements.push({
1767
containerId,
1736
-@@ -5630,6 +5638,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1768
+@@ -4957,12 +4965,26 @@ var ContainerLayoutCoordinator = typedMemo(function ContainerLayoutCoordinatorCo
1769
+ }) {
1770
+ const ctx = useStateContext();
1771
+ const [containerLayoutEpoch] = useArr$(["containerLayoutEpoch"]);
1772
++ const layoutPasses = React3.useRef(0);
1773
+ React3.useLayoutEffect(() => {
1774
+- {
1775
+- const targetContainerIds = getContainerLayoutEffectScope(ctx);
1776
+- if (targetContainerIds !== void 0) {
1777
+- measureContainersInLayoutEffect(ctx, targetContainerIds);
1778
+- }
1779
++ const targetContainerIds = getContainerLayoutEffectScope(ctx);
1780
++ if (targetContainerIds === void 0) return;
1781
++ if (layoutPasses.current === 0) {
1782
++ queueMicrotask(() => { layoutPasses.current = 0; });
1783
++ }
1784
++ // Correcting large estimates can mount one row per commit. Bound the
1785
++ // synchronous chain below React's nested-update limit, then keep measuring
1786
++ // the latest pending rows on the next frame. Idle lists schedule no work.
1787
++ if (layoutPasses.current++ < 8) {
1788
++ measureContainersInLayoutEffect(ctx, targetContainerIds);
1789
++ } else {
1790
++ ctx.pendingContainerIds = targetContainerIds;
1791
++ ctx.state.scheduledWork.frame(() => {
1792
++ const pendingIds = getContainerLayoutEffectScope(ctx);
1793
++ if (pendingIds !== void 0) {
1794
++ measureContainersInLayoutEffect(ctx, pendingIds);
1795
++ }
1796
++ }, "containerLayout");
1797
+ }
1798
+ }, [ctx, containerLayoutEpoch]);
1799
+ return children;
1800
+@@ -5630,6 +5652,18 @@ var ContainerSlot = typedMemo(function ContainerSlot2(props) {
1801
});
1802
1803
// src/utils/reordering.ts
@@ -1752,7 +1816,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..cff49dc5c769cab264b8527a26885129
1816
function sortDOMElements(container, indexByElement) {
1817
const elements = Array.from(container.children);
1818
if (elements.length <= 1) return elements;
1755
-@@ -5669,9 +5689,9 @@ function sortDOMElements(container, indexByElement) {
1819
+@@ -5669,9 +5703,9 @@ function sortDOMElements(container, indexByElement) {
1820
}
1821
}
1822
if (nextStableElement) {
@@ -1764,7 +1828,7 @@ index 95465f2ab89ce41a10553f58af83618f7310e83c..cff49dc5c769cab264b8527a26885129
1828
}
1829
}
1830
}
1767
-@@ -6425,8 +6445,8 @@ function ScrollAdjust() {
1831
+@@ -6425,8 +6459,8 @@ function ScrollAdjust() {
1832
window.getComputedStyle(contentNode)[axis.paddingEndProp]
1833
);
1834
const temporaryPaddingEnd = `${(currentPaddingEnd || 0) + pad}px`;
pnpm-lock.yaml
+4
-4
@@ -333,7 +333,7 @@ patchedDependencies:
333
'@expo/metro-config@58.0.14': 90fa980e8b6480631fb2fbb04559834e3c612db40c550cd828f11be297d8d760
334
'@expo/ui@58.0.20': 5a26480373850c1a7943919aa21f904151b335a0cb01042109e0746def37923e
335
'@ff-labs/fff-node@0.11.0': cc71fcec015f4d39bc96ae2e2bf6b0ca678124c722c66a7841efce9d34b5983c
336
- '@legendapp/list@3.3.5': 7b62e3a8814279aef02146d986ba3b50763ffd04e38ff36ce132e2065600ade3
336
+ '@legendapp/list@3.3.5': 011a862a7116ec5b5f4bba17d37bc58c9b5a8f64a6a9f527345f316ce9c96e63
337
'@pierre/diffs@1.5.2': 2ec81ba1e8ce4681095a3473c2bf78e630417740c622720ef624febb467c25fc
338
'@react-native-ai/apple@0.12.0': 2d09870c2848d185cb05b53ed823a46e12dba519324d8dd8e584e28731990f9d
339
'@react-native-menu/menu@2.0.0': a4866ecfcd44f318043de839d20110c17e14909004900f002ffe12050376f2ba
@@ -515,7 +515,7 @@ importers:
515
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)
516
'@legendapp/list':
517
specifier: 'catalog:'
518
- version: 3.3.5(patch_hash=7b62e3a8814279aef02146d986ba3b50763ffd04e38ff36ce132e2065600ade3)(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)
518
+ 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)
519
'@material/material-color-utilities':
520
specifier: 0.3.0
521
version: 0.3.0
@@ -1012,7 +1012,7 @@ importers:
1012
version: 0.9.0
1013
'@legendapp/list':
1014
specifier: 'catalog:'
1015
- version: 3.3.5(patch_hash=7b62e3a8814279aef02146d986ba3b50763ffd04e38ff36ce132e2065600ade3)(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)
1015
+ 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)
1016
'@noble/hashes':
1017
specifier: 'catalog:'
1018
version: 1.8.0
@@ -14926,7 +14926,7 @@ snapshots:
14926
dependencies:
14927
jsbi: 4.3.2
14928
14929
- '@legendapp/list@3.3.5(patch_hash=7b62e3a8814279aef02146d986ba3b50763ffd04e38ff36ce132e2065600ade3)(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)':
14929
+ '@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)':
14930
dependencies:
14931
react: 19.3.0
14932
use-sync-external-store: 1.6.0(react@19.3.0)