From bfabc5765245aa4838d02a9478a37deb761d78ff Mon Sep 17 00:00:00 2001 From: 777genius Date: Sun, 31 May 2026 07:25:14 +0300 Subject: [PATCH] perf(renderer): trim snapshot sharing type checks --- .../team/teamSnapshotStructuralSharing.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/renderer/store/team/teamSnapshotStructuralSharing.ts b/src/renderer/store/team/teamSnapshotStructuralSharing.ts index fab4e90c..6b294054 100644 --- a/src/renderer/store/team/teamSnapshotStructuralSharing.ts +++ b/src/renderer/store/team/teamSnapshotStructuralSharing.ts @@ -1,11 +1,12 @@ import type { TeamViewSnapshot } from '@shared/types'; -function isPlainObject(value: unknown): value is Record { - if (value == null || typeof value !== 'object') { +function arePlainObjectPair(previous: object, next: object): boolean { + const previousPrototype = Object.getPrototypeOf(previous); + if (previousPrototype !== Object.prototype && previousPrototype !== null) { return false; } - const prototype = Object.getPrototypeOf(value); - return prototype === Object.prototype || prototype === null; + const nextPrototype = Object.getPrototypeOf(next); + return nextPrototype === Object.prototype || nextPrototype === null; } export function structurallySharePlainValue(previous: T, next: T): T { @@ -13,6 +14,15 @@ export function structurallySharePlainValue(previous: T, next: T): T { return previous; } + if ( + previous == null || + next == null || + typeof previous !== 'object' || + typeof next !== 'object' + ) { + return next; + } + if (Array.isArray(previous) && Array.isArray(next)) { const hasLengthChange = previous.length !== next.length; let result: unknown[] | null = hasLengthChange ? new Array(next.length) : null; @@ -35,7 +45,7 @@ export function structurallySharePlainValue(previous: T, next: T): T { return result ? (result as T) : previous; } - if (isPlainObject(previous) && isPlainObject(next)) { + if (arePlainObjectPair(previous, next)) { const previousRecord = previous as Record; const nextRecord = next as Record; const previousKeys = Object.keys(previousRecord);