mirror of
https://github.com/zhom/donutbrowser.git
synced 2026-09-28 12:12:14 +02:00
refactor: reduce rerenders
This commit is contained in:
@@ -868,8 +868,12 @@ export function ProfilesDataTable({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Fetch traffic snapshots for running profiles (lightweight, real-time data)
|
// Fetch traffic snapshots for running profiles (lightweight, real-time data)
|
||||||
// Using runningProfiles.size as dependency to avoid Set reference comparison issues
|
// Convert Set to sorted array to avoid Set reference comparison issues in dependencies
|
||||||
const runningCount = runningProfiles.size;
|
const runningProfileIds = React.useMemo(
|
||||||
|
() => Array.from(runningProfiles).sort(),
|
||||||
|
[runningProfiles],
|
||||||
|
);
|
||||||
|
const runningCount = runningProfileIds.length;
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!browserState.isClient) return;
|
if (!browserState.isClient) return;
|
||||||
|
|
||||||
@@ -887,7 +891,7 @@ export function ProfilesDataTable({
|
|||||||
for (const snapshot of allSnapshots) {
|
for (const snapshot of allSnapshots) {
|
||||||
if (snapshot.profile_id) {
|
if (snapshot.profile_id) {
|
||||||
// Only keep snapshots for profiles that are currently running
|
// Only keep snapshots for profiles that are currently running
|
||||||
if (runningProfiles.has(snapshot.profile_id)) {
|
if (runningProfileIds.includes(snapshot.profile_id)) {
|
||||||
const existing = newSnapshots[snapshot.profile_id];
|
const existing = newSnapshots[snapshot.profile_id];
|
||||||
if (!existing || snapshot.last_update > existing.last_update) {
|
if (!existing || snapshot.last_update > existing.last_update) {
|
||||||
newSnapshots[snapshot.profile_id] = snapshot;
|
newSnapshots[snapshot.profile_id] = snapshot;
|
||||||
@@ -904,7 +908,7 @@ export function ProfilesDataTable({
|
|||||||
void fetchTrafficSnapshots();
|
void fetchTrafficSnapshots();
|
||||||
const interval = setInterval(fetchTrafficSnapshots, 1000);
|
const interval = setInterval(fetchTrafficSnapshots, 1000);
|
||||||
return () => clearInterval(interval);
|
return () => clearInterval(interval);
|
||||||
}, [browserState.isClient, runningCount, runningProfiles]);
|
}, [browserState.isClient, runningCount, runningProfileIds]);
|
||||||
|
|
||||||
// Clean up snapshots for profiles that are no longer running
|
// Clean up snapshots for profiles that are no longer running
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
@@ -914,7 +918,7 @@ export function ProfilesDataTable({
|
|||||||
const cleaned: Record<string, TrafficSnapshot> = {};
|
const cleaned: Record<string, TrafficSnapshot> = {};
|
||||||
for (const [profileId, snapshot] of Object.entries(prev)) {
|
for (const [profileId, snapshot] of Object.entries(prev)) {
|
||||||
// Only keep snapshots for profiles that are currently running
|
// Only keep snapshots for profiles that are currently running
|
||||||
if (runningProfiles.has(profileId)) {
|
if (runningProfileIds.includes(profileId)) {
|
||||||
cleaned[profileId] = snapshot;
|
cleaned[profileId] = snapshot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -924,7 +928,7 @@ export function ProfilesDataTable({
|
|||||||
}
|
}
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
}, [browserState.isClient, runningProfiles]);
|
}, [browserState.isClient, runningProfileIds]);
|
||||||
|
|
||||||
// Clear launching/stopping spinners when backend reports running status changes
|
// Clear launching/stopping spinners when backend reports running status changes
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user