Skip to content

Commit 38d3c53

Browse files
flambohmaria-rcks
authored andcommitted
fix(web): collapsing the working history at the bottom no longer doubles its rows (#31272)
Collapsing work history at the bottom let deferred list measurements fight scroll anchoring. Anchor only on opening and opt into immediate web shrink measurements while collapsing.
1 parent 7ac939e commit 38d3c53

3 files changed

Lines changed: 68 additions & 9 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
611611
const list = listRef.current;
612612
if (list) {
613613
list.cancelScroll();
614-
list.anchorVisibleContent({ key: "working-indicator-row" });
614+
if (workingHistoryKey !== key) list.anchorVisibleContent({ key: "working-indicator-row" });
615615
}
616616
setWorkingHistoryKey((current) => (current === key ? null : key));
617617
};
@@ -1702,6 +1702,7 @@ const ConversationTimeline = memo(function ConversationTimeline({
17021702
: maintainVisibleContentPosition
17031703
}
17041704
maintainScrollAtEndThreshold={1}
1705+
immediateWebShrinks={workingHistoryCollapsing}
17051706
onScroll={handleScroll}
17061707
onItemSizeChanged={scheduleMinimapRefresh}
17071708
onMetricsChange={scheduleMinimapRefresh}

‎patches/@legendapp__list@3.7.2.patch‎

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
1+
diff --git a/react.d.ts b/react.d.ts
2+
index 358fcd7..e3c7de6 100644
3+
--- a/react.d.ts
4+
+++ b/react.d.ts
5+
@@ -314,6 +314,7 @@ interface LegendListSpecificProps<ItemT, TItemType extends string | undefined> {
6+
* @default 0.1
7+
*/
8+
maintainScrollAtEndThreshold?: number;
9+
+ immediateWebShrinks?: boolean;
10+
/**
11+
* Maintains visibility of content.
12+
* - size (default: true) stabilizes during size/layout changes while scrolling.
113
diff --git a/react.js b/react.js
2-
index 5155454..2885128 100644
14+
index 5155454..b63bce6 100644
315
--- a/react.js
416
+++ b/react.js
517
@@ -3489,6 +3489,12 @@ function abortBootstrapInitialScroll(ctx) {
@@ -42,7 +54,14 @@ index 5155454..2885128 100644
4254
const previousRect = prevRect != null ? prevRect : getContainerLayoutBaseline(element);
4355
const didSizeChange = previousRect === void 0 || rectObserved.width !== previousRect.width || rectObserved.height !== previousRect.height;
4456
prevRect = rectObserved;
45-
@@ -6296,7 +6302,7 @@ function processContainerLayout({ containerId, ctx, rectangle, ref, state }) {
57+
@@ -6290,13 +6296,13 @@ function processContainerLayout({ containerId, ctx, rectangle, ref, state }) {
58+
size: layout
59+
});
60+
};
61+
- const shouldDeferWebShrinkLayoutUpdate = !isInMVCPActiveMode(listState) && previousSize !== void 0 && size + 1 < previousSize;
62+
+ const shouldDeferWebShrinkLayoutUpdate = !listState.props.immediateWebShrinks && !isInMVCPActiveMode(listState) && previousSize !== void 0 && size + 1 < previousSize;
63+
if (shouldDeferWebShrinkLayoutUpdate) {
64+
scheduleWebShrinkMeasurement(state, () => {
4665
var _a4;
4766
if (state.itemKey === currentItemKey) {
4867
const element = ref.current;
@@ -51,8 +70,24 @@ index 5155454..2885128 100644
5170
if (rect) {
5271
layout = { height: rect.height, width: rect.width };
5372
}
73+
@@ -9133,6 +9139,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
74+
getFixedItemSize,
75+
getItemType,
76+
horizontal,
77+
+ immediateWebShrinks,
78+
rtl,
79+
estimatedHeaderSize,
80+
initialScrollAtEnd = false,
81+
@@ -9431,6 +9438,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
82+
hasExternalScroll,
83+
hideItemsUntilMeasured: experimental_hideItemsUntilMeasured,
84+
horizontal: !!horizontal,
85+
+ immediateWebShrinks: !!immediateWebShrinks,
86+
itemsAreEqual,
87+
keyExtractor: useWrapIfItem(keyExtractor),
88+
maintainScrollAtEnd: maintainScrollAtEndConfig,
5489
diff --git a/react.mjs b/react.mjs
55-
index ce08abe..2c764cb 100644
90+
index ce08abe..294988d 100644
5691
--- a/react.mjs
5792
+++ b/react.mjs
5893
@@ -3468,6 +3468,12 @@ function abortBootstrapInitialScroll(ctx) {
@@ -95,7 +130,14 @@ index ce08abe..2c764cb 100644
95130
const previousRect = prevRect != null ? prevRect : getContainerLayoutBaseline(element);
96131
const didSizeChange = previousRect === void 0 || rectObserved.width !== previousRect.width || rectObserved.height !== previousRect.height;
97132
prevRect = rectObserved;
98-
@@ -6275,7 +6281,7 @@ function processContainerLayout({ containerId, ctx, rectangle, ref, state }) {
133+
@@ -6269,13 +6275,13 @@ function processContainerLayout({ containerId, ctx, rectangle, ref, state }) {
134+
size: layout
135+
});
136+
};
137+
- const shouldDeferWebShrinkLayoutUpdate = !isInMVCPActiveMode(listState) && previousSize !== void 0 && size + 1 < previousSize;
138+
+ const shouldDeferWebShrinkLayoutUpdate = !listState.props.immediateWebShrinks && !isInMVCPActiveMode(listState) && previousSize !== void 0 && size + 1 < previousSize;
139+
if (shouldDeferWebShrinkLayoutUpdate) {
140+
scheduleWebShrinkMeasurement(state, () => {
99141
var _a4;
100142
if (state.itemKey === currentItemKey) {
101143
const element = ref.current;
@@ -104,6 +146,22 @@ index ce08abe..2c764cb 100644
104146
if (rect) {
105147
layout = { height: rect.height, width: rect.width };
106148
}
149+
@@ -9112,6 +9118,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
150+
getFixedItemSize,
151+
getItemType,
152+
horizontal,
153+
+ immediateWebShrinks,
154+
rtl,
155+
estimatedHeaderSize,
156+
initialScrollAtEnd = false,
157+
@@ -9410,6 +9417,7 @@ var LegendListInner = typedForwardRef(function LegendListInner2(props, forwarded
158+
hasExternalScroll,
159+
hideItemsUntilMeasured: experimental_hideItemsUntilMeasured,
160+
horizontal: !!horizontal,
161+
+ immediateWebShrinks: !!immediateWebShrinks,
162+
itemsAreEqual,
163+
keyExtractor: useWrapIfItem(keyExtractor),
164+
maintainScrollAtEnd: maintainScrollAtEndConfig,
107165
diff --git a/react-native.js b/react-native.js
108166
index 4af685dfb961eb0c8a4bf1ae9132c9304cf4fa4d..df4ead7ae4f03cd0fbcd99a3df7d95e15b1852b1 100644
109167
--- a/react-native.js

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)