add checks for prevShape existence and remoteShape id in shape sync

This commit is contained in:
KDSBrowne 2024-01-22 17:15:41 +00:00
parent 2fece0bfad
commit f01c55680e

View File

@ -222,8 +222,9 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
});
Object.values(prevShapesRef.current).forEach((remoteShape) => {
if (!remoteShape.id) return;
const localShape = localLookup.get(remoteShape.id);
const prevShape = prevShapesRef.current[remoteShape.id];
// Create a deep clone of remoteShape and remove the isModerator property
const comparisonRemoteShape = deepCloneUsingShallow(remoteShape);
delete comparisonRemoteShape.isModerator;
@ -234,7 +235,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
// If the shape does not exist in local, add it to toAdd
toAdd.push(remoteShape);
}
} else if (!isEqual(localShape, comparisonRemoteShape)) {
} else if (!isEqual(localShape, comparisonRemoteShape) && prevShape) {
// Capture the differences
const diff = {
id: remoteShape.id,
@ -242,7 +243,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
typeName: remoteShape.typeName,
};
if (!selectedShapeIds.includes(diff?.id) && prevShapesRef.current[`${diff?.id}`].meta?.updatedBy !== currentUser?.userId) {
if (!selectedShapeIds.includes(remoteShape.id) && prevShape?.meta?.updatedBy !== currentUser?.userId) {
// Compare each property
Object.keys(remoteShape).forEach((key) => {
if (