Description
Two instances use .sort() which mutates arrays in place. If the source returns a cached/shared array, the sort order can leak across requests or corrupt data held in a Map.
Vercel React Best Practices Rule: js-tosorted-immutable (7.12)
Files to change
1. surfsense_web/app/(home)/changelog/page.tsx (lines 31-36)
const allPages = source.getPages() as ChangelogPageItem[];
const sortedChangelogs = allPages.sort((a, b) => {
const dateA = new Date(a.data.date).getTime();
const dateB = new Date(b.data.date).getTime();
return dateB - dateA;
});
Fix:
const sortedChangelogs = allPages.toSorted((a, b) => {
const dateA = new Date(a.data.date).getTime();
const dateB = new Date(b.data.date).getTime();
return dateB - dateA;
});
2. surfsense_web/hooks/use-comments-sync.ts (lines 119-122)
const replies = (group.replies.get(raw.id) || [])
.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
.map((r) => transformReply(r, memberMap, currentUserId, isOwner));
Fix:
const replies = [...(group.replies.get(raw.id) ?? [])]
.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime())
.map((r) => transformReply(r, memberMap, currentUserId, isOwner));
// Or use .toSorted() if available
Acceptance criteria
- Neither file mutates the source array
- Changelog page still displays entries in reverse chronological order
- Comment replies still display in chronological order
Description
Two instances use
.sort()which mutates arrays in place. If the source returns a cached/shared array, the sort order can leak across requests or corrupt data held in a Map.Vercel React Best Practices Rule:
js-tosorted-immutable(7.12)Files to change
1.
surfsense_web/app/(home)/changelog/page.tsx(lines 31-36)Fix:
2.
surfsense_web/hooks/use-comments-sync.ts(lines 119-122)Fix:
Acceptance criteria