Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/plugins/common/data-source/json-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
$isRangeSelection,
$isTextNode,
IS_CODE,
resetRandomKey,
} from 'lexical';
import { $getRoot } from 'lexical';

Expand Down Expand Up @@ -73,6 +74,13 @@ export default class JSONDataSource extends DataSource {
(state) => {
try {
const root = $parseSerializedNodeImpl(dataObj.root, editor, true, state);
let maxId = -1;
state._nodeMap.keys().forEach((key) => {
if (key === 'root') return;
maxId = Math.max(maxId, Number(key));
});
// make sure to reset random key to avoid id conflicts
resetRandomKey(maxId + 1);
state._nodeMap.set(root.getKey(), root);
} catch (error) {
console.error(error);
Expand Down
Loading