fix(site): resolve all Array.prototype.toSorted and Array.prototype.sort bugs (#17307)

Closes https://github.com/coder/coder/issues/16759

## Changes made
- Replaced all instances of `Array.prototype.toSorted` with
`Array.prototype.sort` to provide better support for older browsers
- Updated all `Array.prototype.sort` calls where necessary to remove
risks of mutation render bugs
- Refactored some code (moved things around, added comments) to make it
more clear that certain `.sort` calls are harmless and don't have any
risks
This commit is contained in:
Michael Smith
2025-04-09 15:17:02 -04:00
committed by GitHub
parent d17bcc727b
commit a03a54dd14
9 changed files with 87 additions and 88 deletions
@@ -13,9 +13,9 @@ export const mergeTimeRanges = (ranges: TimeRange[]): TimeRange => {
.sort((a, b) => a.startedAt.getTime() - b.startedAt.getTime());
const start = sortedDurations[0].startedAt;
const sortedEndDurations = ranges
.slice()
.sort((a, b) => a.endedAt.getTime() - b.endedAt.getTime());
const sortedEndDurations = [...ranges].sort(
(a, b) => a.endedAt.getTime() - b.endedAt.getTime(),
);
const end = sortedEndDurations[sortedEndDurations.length - 1].endedAt;
return { startedAt: start, endedAt: end };
};