Skip to content

Commit 2654ee4

Browse files
committed
fix(pages): fix deep arrow serialization
1 parent a1e9a60 commit 2654ee4

File tree

1 file changed

+82
-33
lines changed

1 file changed

+82
-33
lines changed

apps/client/src/code/pages/serialization.ts

Lines changed: 82 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,36 +135,20 @@ export class Serialization {
135135
arrowMap: new Map(),
136136
};
137137

138-
for (const note of input.notes) {
139-
for (const arrow of internals.pages.react.page.arrows.fromIds(
140-
Array.from(note.incomingArrowIds),
141-
)) {
142-
input.arrows.push(arrow);
143-
}
144-
145-
for (const arrow of internals.pages.react.page.arrows.fromIds(
146-
Array.from(note.outgoingArrowIds),
147-
)) {
148-
input.arrows.push(arrow);
149-
}
150-
}
151-
152-
this._serializeRegion(input, aux.serialObj.root, aux);
138+
this._serializeRegionNotes(input, aux.serialObj.root, aux);
139+
this._serializeRegionArrows(input, aux.serialObj.root, aux);
153140

154141
return aux.serialObj;
155142
}
156-
private _serializeRegion(
143+
144+
private _serializeRegionNotes(
157145
region: IRegionElemsOutput,
158146
serialRegion: ISerialRegionOutput,
159147
aux: SerializationAux,
160148
) {
161149
for (const note of region.notes) {
162150
this._serializeNote(note, serialRegion, aux);
163151
}
164-
165-
for (const arrow of region.arrows) {
166-
this._serializeArrow(arrow, serialRegion, aux);
167-
}
168152
}
169153
private _serializeNote(
170154
note: PageNote,
@@ -203,7 +187,36 @@ export class Serialization {
203187
serialRegion.noteIdxs.push(noteIndex);
204188
aux.noteMap.set(note.id, noteIndex);
205189

206-
this._serializeRegion(note.react, serialNote, aux);
190+
this._serializeRegionNotes(note.react, serialNote, aux);
191+
}
192+
193+
private _serializeRegionArrows(
194+
region: IRegionElemsOutput,
195+
serialRegion: ISerialRegionOutput,
196+
aux: SerializationAux,
197+
note?: PageNote,
198+
) {
199+
for (const arrow of [
200+
...region.arrows,
201+
202+
...internals.pages.react.page.arrows.fromIds(
203+
Array.from(note?.incomingArrowIds ?? []),
204+
),
205+
...internals.pages.react.page.arrows.fromIds(
206+
Array.from(note?.outgoingArrowIds ?? []),
207+
),
208+
]) {
209+
this._serializeArrow(arrow, serialRegion, aux);
210+
}
211+
212+
for (const note of region.notes) {
213+
this._serializeRegionArrows(
214+
note.react,
215+
aux.serialObj.notes[aux.noteMap.get(note.id)!],
216+
aux,
217+
note,
218+
);
219+
}
207220
}
208221
private _serializeArrow(
209222
arrow: PageArrow,
@@ -256,7 +269,15 @@ export class Serialization {
256269
});
257270

258271
internals.pages.react.page.collab.doc.transact(() => {
259-
this._deserializeRegion(
272+
this._deserializeRegionNotes(
273+
serialObj.root,
274+
serialObj,
275+
noteMap,
276+
destRegion.id,
277+
fakeRegionCollab,
278+
);
279+
280+
this._deserializeRegionArrows(
260281
serialObj.root,
261282
serialObj,
262283
noteMap,
@@ -285,7 +306,7 @@ export class Serialization {
285306
),
286307
};
287308
}
288-
private _deserializeRegion(
309+
private _deserializeRegionNotes(
289310
serialRegion: ISerialRegionOutput,
290311
serialObj: ISerialObjectOutput,
291312
noteMap: Map<number, string>,
@@ -302,16 +323,8 @@ export class Serialization {
302323
destRegionCollab,
303324
);
304325
}
305-
306-
for (const arrowIndex of serialRegion.arrowIdxs) {
307-
this._deserializeArrow(
308-
serialObj.arrows[arrowIndex],
309-
noteMap,
310-
destRegionId,
311-
destRegionCollab,
312-
);
313-
}
314326
}
327+
315328
private _deserializeNote(
316329
serialNote: ISerialNoteOutput,
317330
noteIndex: number,
@@ -356,10 +369,46 @@ export class Serialization {
356369

357370
destRegionCollab.noteIds.push(noteId);
358371

359-
this._deserializeRegion(serialNote, serialObj, noteMap, noteId, noteCollab);
372+
this._deserializeRegionNotes(
373+
serialNote,
374+
serialObj,
375+
noteMap,
376+
noteId,
377+
noteCollab,
378+
);
360379

361380
internals.pages.react.page.notes.react.collab[noteId] = noteCollab;
362381
}
382+
383+
private _deserializeRegionArrows(
384+
serialRegion: ISerialRegionOutput,
385+
serialObj: ISerialObjectOutput,
386+
noteMap: Map<number, string>,
387+
destRegionId: string,
388+
destRegionCollab: IRegionCollabOutput,
389+
) {
390+
for (const arrowIndex of serialRegion.arrowIdxs) {
391+
this._deserializeArrow(
392+
serialObj.arrows[arrowIndex],
393+
noteMap,
394+
destRegionId,
395+
destRegionCollab,
396+
);
397+
}
398+
399+
for (const noteIndex of serialRegion.noteIdxs) {
400+
const noteId = noteMap.get(noteIndex)!;
401+
const noteCollab = internals.pages.react.page.notes.react.collab[noteId];
402+
403+
this._deserializeRegionArrows(
404+
serialObj.notes[noteIndex],
405+
serialObj,
406+
noteMap,
407+
noteId,
408+
noteCollab,
409+
);
410+
}
411+
}
363412
private _deserializeArrow(
364413
serialArrow: ISerialArrowOutput,
365414
noteMap: Map<number, string>,

0 commit comments

Comments
 (0)