This commit is contained in:
Timothy Jaeryang Baek 2026-09-27 23:07:52 +04:00
parent 31a09a1eeb
commit b39abad5c2
3 changed files with 35 additions and 4 deletions

View file

@ -1,7 +1,7 @@
<script lang="ts">
import { marked } from 'marked';
import DOMPurify from 'dompurify';
import equal from 'fast-deep-equal';
import { equalEditorJSON } from '$lib/utils/editorJson';
import { showCallOverlay, skills, terminalSkills } from '$lib/stores';
marked.use({
@ -1380,7 +1380,7 @@
}
if (json) {
if (!equal(value, jsonValue)) {
if (!equalEditorJSON(value, jsonValue)) {
editor.commands.setContent(value);
selectTemplate();
}

View file

@ -8,7 +8,7 @@
import { marked } from 'marked';
import { toast } from 'svelte-sonner';
import equal from 'fast-deep-equal';
import { equalEditorJSON } from '$lib/utils/editorJson';
import { goto, onNavigate } from '$app/navigation';
@ -340,7 +340,7 @@
}
function areContentsEqual(a, b) {
return equal(a, b);
return equalEditorJSON(a, b);
}
function insertNoteVersion(note) {

View file

@ -0,0 +1,31 @@
// Editor JSON can contain ProseMirror's null-prototype attributes, which fast-deep-equal
// cannot compare. Keep this scoped to JSON data, with reference checks and early exits.
export function equalEditorJSON(a: unknown, b: unknown): boolean {
if (a === b) return true;
if (!a || !b || typeof a !== 'object' || typeof b !== 'object') return false;
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!equalEditorJSON(a[i], b[i])) return false;
}
return true;
}
if (Array.isArray(b)) return false;
const left = a as Record<string, unknown>;
const right = b as Record<string, unknown>;
const keys = Object.keys(left);
if (keys.length !== Object.keys(right).length) return false;
for (const key of keys) {
if (
!Object.prototype.hasOwnProperty.call(right, key) ||
!equalEditorJSON(left[key], right[key])
) {
return false;
}
}
return true;
}