Skip to content

Commit 62c6bdd

Browse files
Fix list items height calculation to prevent crashes (infinite re-renders) (#8254)
Fix #5933 Fix #6189
1 parent 7463917 commit 62c6bdd

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
lines changed

newIDE/app/src/AssetStore/BehaviorStore/BehaviorListItem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export const BehaviorListItem = ({
8989
const containerRef = React.useRef<?HTMLDivElement>(null);
9090
React.useLayoutEffect(() => {
9191
if (containerRef.current)
92-
onHeightComputed(containerRef.current.getBoundingClientRect().height);
92+
onHeightComputed(
93+
Math.ceil(containerRef.current.getBoundingClientRect().height)
94+
);
9395
});
9496

9597
const renderField = (field: 'description' | 'fullName') => {

newIDE/app/src/AssetStore/ExtensionStore/ExtensionListItem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ export const ExtensionListItem = ({
6060
const containerRef = React.useRef<?HTMLDivElement>(null);
6161
React.useLayoutEffect(() => {
6262
if (containerRef.current)
63-
onHeightComputed(containerRef.current.getBoundingClientRect().height);
63+
onHeightComputed(
64+
Math.ceil(containerRef.current.getBoundingClientRect().height)
65+
);
6466
});
6567

6668
const renderExtensionField = (field: 'shortDescription' | 'fullName') => {

newIDE/app/src/AssetStore/NewObjectFromScratch.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ const TitleListItem = ({ value, onHeightComputed }: TitleListItemProps) => {
9999
const containerRef = React.useRef<?HTMLDivElement>(null);
100100
React.useLayoutEffect(() => {
101101
if (containerRef.current)
102-
onHeightComputed(containerRef.current.getBoundingClientRect().height);
102+
onHeightComputed(
103+
Math.ceil(containerRef.current.getBoundingClientRect().height)
104+
);
103105
});
104106

105107
return (

newIDE/app/src/AssetStore/ObjectListItem.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export const ObjectListItem = ({
5959
const containerRef = React.useRef<?HTMLDivElement>(null);
6060
React.useLayoutEffect(() => {
6161
if (containerRef.current)
62-
onHeightComputed(containerRef.current.getBoundingClientRect().height);
62+
onHeightComputed(
63+
Math.ceil(containerRef.current.getBoundingClientRect().height)
64+
);
6365
});
6466

6567
const renderField = (field: 'description' | 'fullName') => {

newIDE/app/src/UI/Search/ListSearchResults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const ListSearchResults = <SearchItem>({
8484
{renderSearchItem(searchItem, height => {
8585
const heightWasUpdated = onItemHeightComputed(searchItem, height);
8686
if (heightWasUpdated && grid.current) {
87-
grid.current.recomputeGridSize(0, rowIndex);
87+
grid.current.recomputeGridSize({ rowIndex });
8888
}
8989
})}
9090
</div>
@@ -138,7 +138,7 @@ export const ListSearchResults = <SearchItem>({
138138
ref={el => {
139139
if (el) {
140140
// Ensure the grid is recomputed for heights once it is rendered.
141-
el.recomputeGridSize(0, 0);
141+
el.recomputeGridSize();
142142
}
143143
grid.current = el;
144144
}}

0 commit comments

Comments
 (0)