fix: restoreElementWithProperties drops "parent" property (#5742)

Co-authored-by: Yosyp Buchma <yo@yosyp.co>
Co-authored-by: dwelle <luzar.david@gmail.com>
This commit is contained in:
Joseph Buchma 2022-10-08 21:42:05 +03:00 committed by GitHub
parent 76cf560914
commit e9a224a0de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 19 deletions

View file

@ -18,6 +18,7 @@ import throttle from "lodash.throttle";
import { newElementWith } from "../../element/mutateElement";
import { BroadcastedExcalidrawElement } from "./reconciliation";
import { encryptData } from "../../data/encryption";
import { PRECEDING_ELEMENT_KEY } from "../../constants";
class Portal {
collab: TCollabClass;
@ -152,7 +153,7 @@ class Portal {
acc.push({
...element,
// z-index info for the reconciler
parent: idx === 0 ? "^" : elements[idx - 1]?.id,
[PRECEDING_ELEMENT_KEY]: idx === 0 ? "^" : elements[idx - 1]?.id,
});
}
return acc;

View file

@ -1,3 +1,4 @@
import { PRECEDING_ELEMENT_KEY } from "../../constants";
import { ExcalidrawElement } from "../../element/types";
import { AppState } from "../../types";
@ -6,7 +7,7 @@ export type ReconciledElements = readonly ExcalidrawElement[] & {
};
export type BroadcastedExcalidrawElement = ExcalidrawElement & {
parent?: string;
[PRECEDING_ELEMENT_KEY]?: string;
};
const shouldDiscardRemoteElement = (
@ -71,8 +72,8 @@ export const reconcileElements = (
const local = localElementsData[remoteElement.id];
if (shouldDiscardRemoteElement(localAppState, local?.[0], remoteElement)) {
if (remoteElement.parent) {
delete remoteElement.parent;
if (remoteElement[PRECEDING_ELEMENT_KEY]) {
delete remoteElement[PRECEDING_ELEMENT_KEY];
}
continue;
@ -92,10 +93,12 @@ export const reconcileElements = (
// parent may not be defined in case the remote client is running an older
// excalidraw version
const parent =
remoteElement.parent || remoteElements[remoteElementIdx - 1]?.id || null;
remoteElement[PRECEDING_ELEMENT_KEY] ||
remoteElements[remoteElementIdx - 1]?.id ||
null;
if (parent != null) {
delete remoteElement.parent;
delete remoteElement[PRECEDING_ELEMENT_KEY];
// ^ indicates the element is the first in elements array
if (parent === "^") {