Skip to content

Commit c8d6eba

Browse files
committed
Preserve the original index when sorting suspended by
1 parent ead9218 commit c8d6eba

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementSuspendedBy.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,31 @@ type Props = {
300300
store: Store,
301301
};
302302

303-
function compareTime(a: SerializedAsyncInfo, b: SerializedAsyncInfo): number {
304-
const ioA = a.awaited;
305-
const ioB = b.awaited;
303+
function withIndex(
304+
value: SerializedAsyncInfo,
305+
index: number,
306+
): {
307+
index: number,
308+
value: SerializedAsyncInfo,
309+
} {
310+
return {
311+
index,
312+
value,
313+
};
314+
}
315+
316+
function compareTime(
317+
a: {
318+
index: number,
319+
value: SerializedAsyncInfo,
320+
},
321+
b: {
322+
index: number,
323+
value: SerializedAsyncInfo,
324+
},
325+
): number {
326+
const ioA = a.value.awaited;
327+
const ioB = b.value.awaited;
306328
if (ioA.start === ioB.start) {
307329
return ioA.end - ioB.end;
308330
}
@@ -364,7 +386,8 @@ export default function InspectedElementSuspendedBy({
364386
minTime = maxTime - 25;
365387
}
366388

367-
const sortedSuspendedBy = suspendedBy === null ? [] : suspendedBy.slice(0);
389+
const sortedSuspendedBy =
390+
suspendedBy === null ? [] : suspendedBy.map(withIndex);
368391
sortedSuspendedBy.sort(compareTime);
369392

370393
let unknownSuspenders = null;
@@ -407,11 +430,11 @@ export default function InspectedElementSuspendedBy({
407430
<ButtonIcon type="copy" />
408431
</Button>
409432
</div>
410-
{sortedSuspendedBy.map((asyncInfo, index) => (
433+
{sortedSuspendedBy.map(({value, index}) => (
411434
<SuspendedByRow
412435
key={index}
413436
index={index}
414-
asyncInfo={asyncInfo}
437+
asyncInfo={value}
415438
bridge={bridge}
416439
element={element}
417440
inspectedElement={inspectedElement}

0 commit comments

Comments
 (0)