mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[DevTools] Preserve the original index when sorting suspended by (#34829)
The index is both used as the key and for hydration purposes. Previously we didn't preserve the index when sorting so the index didn't line up which caused hydration to be the wrong slot when sorted.
This commit is contained in:
Vendored
+29
-6
@@ -300,9 +300,31 @@ type Props = {
|
||||
store: Store,
|
||||
};
|
||||
|
||||
function compareTime(a: SerializedAsyncInfo, b: SerializedAsyncInfo): number {
|
||||
const ioA = a.awaited;
|
||||
const ioB = b.awaited;
|
||||
function withIndex(
|
||||
value: SerializedAsyncInfo,
|
||||
index: number,
|
||||
): {
|
||||
index: number,
|
||||
value: SerializedAsyncInfo,
|
||||
} {
|
||||
return {
|
||||
index,
|
||||
value,
|
||||
};
|
||||
}
|
||||
|
||||
function compareTime(
|
||||
a: {
|
||||
index: number,
|
||||
value: SerializedAsyncInfo,
|
||||
},
|
||||
b: {
|
||||
index: number,
|
||||
value: SerializedAsyncInfo,
|
||||
},
|
||||
): number {
|
||||
const ioA = a.value.awaited;
|
||||
const ioB = b.value.awaited;
|
||||
if (ioA.start === ioB.start) {
|
||||
return ioA.end - ioB.end;
|
||||
}
|
||||
@@ -364,7 +386,8 @@ export default function InspectedElementSuspendedBy({
|
||||
minTime = maxTime - 25;
|
||||
}
|
||||
|
||||
const sortedSuspendedBy = suspendedBy === null ? [] : suspendedBy.slice(0);
|
||||
const sortedSuspendedBy =
|
||||
suspendedBy === null ? [] : suspendedBy.map(withIndex);
|
||||
sortedSuspendedBy.sort(compareTime);
|
||||
|
||||
let unknownSuspenders = null;
|
||||
@@ -407,11 +430,11 @@ export default function InspectedElementSuspendedBy({
|
||||
<ButtonIcon type="copy" />
|
||||
</Button>
|
||||
</div>
|
||||
{sortedSuspendedBy.map((asyncInfo, index) => (
|
||||
{sortedSuspendedBy.map(({value, index}) => (
|
||||
<SuspendedByRow
|
||||
key={index}
|
||||
index={index}
|
||||
asyncInfo={asyncInfo}
|
||||
asyncInfo={value}
|
||||
bridge={bridge}
|
||||
element={element}
|
||||
inspectedElement={inspectedElement}
|
||||
|
||||
Reference in New Issue
Block a user