Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

fix(ok): reschedule the WYSIWYG lint pass on content-equal rebuilds (#3248)

mike-inkeep8f72b7e94e82
diff --git a/.changeset/lint-decoration-content-equal-rebuild.md b/.changeset/lint-decoration-content-equal-rebuild.md
new file mode 100644
index 000000000..3c66a73e9
--- /dev/null
+++ b/.changeset/lint-decoration-content-equal-rebuild.md
@@ -0,0 +1,5 @@
+---
+"@inkeep/open-knowledge": patch
+---
+
+WYSIWYG lint squiggles no longer vanish permanently when an agent write replaces a document with an unchanged body (for example a frontmatter-only fix). The replace could reach the editor as new nodes carrying identical content; the decoration pass compared content, read it as "nothing changed", and never repainted the marks the replace had destroyed. The pass now reschedules on any transaction that carried real steps.
diff --git a/packages/app/src/editor/extensions/markdown-lint-decorations.test.ts b/packages/app/src/editor/extensions/markdown-lint-decorations.test.ts
index 1c9c053cb..1f8ff76ba 100644
--- a/packages/app/src/editor/extensions/markdown-lint-decorations.test.ts
+++ b/packages/app/src/editor/extensions/markdown-lint-decorations.test.ts
@@ -15,6 +15,7 @@ import {
sharedExtensions as coreExtensions,
DEFAULT_LINTER_CONFIG,
type LintDiagnostic,
+ type LinterConfig,
MarkdownManager,
} from '@inkeep/open-knowledge-core';
import { Editor } from '@tiptap/core';
@@ -406,3 +407,74 @@ describe('Problems-row navigation — scroll suppression', () => {
expect(scrollIntoView).toHaveBeenCalledTimes(1);
});
});
+
+describe('decoration recovery after a content-equal rebuild', () => {
+ const DOC = 'lint-rebuild-doc';
+ /** The hard tab trips MD010 — the same body-anchored rule the e2e fixtures use. */
+ const BODY = '# Heading\n\nfirst paragraph\n\n\tindented with a hard tab\n';
+ const ENABLED_CONFIG: LinterConfig = {
+ enabled: true,
+ plugins: {
+ ...DEFAULT_LINTER_CONFIG.plugins,
+ markdownlint: { enabled: true, rules: { default: true } },
+ },
+ };
+ let editor: Editor | null = null;
+ let host: HTMLElement | null = null;
+ let originalFetch: typeof globalThis.fetch;
+
+ beforeEach(() => {
+ originalFetch = globalThis.fetch;
+ globalThis.fetch = vi.fn(async () =>
+ Response.json({ effective: ENABLED_CONFIG }),
+ ) as unknown as typeof fetch;
+ host = document.createElement('div');
+ document.body.appendChild(host);
+ editor = new Editor({
+ element: host,
+ extensions: [
+ ...coreExtensions,
+ MarkdownLintDecorations.configure({ docName: DOC, getSource: () => BODY }),
+ ],
+ content: md.parse(BODY),
+ });
+ });
+
+ afterEach(() => {
+ editor?.destroy();
+ editor = null;
+ host?.remove();
+ host = null;
+ globalThis.fetch = originalFetch;
+ });
+
+ const decoratedBlocks = () => host?.querySelectorAll('.ok-lint-block').length ?? 0;
+
+ test('a content-equal full replace reschedules the pass instead of orphaning the squiggle', async () => {
+ const ed = editor;
+ if (!ed) throw new Error('editor not mounted');
+ await vi.waitFor(() => expect(decoratedBlocks()).toBe(1), { timeout: 5_000 });
+ // Drain any pass the mount-time transactions already debounced: a pending
+ // timer would repaint after the replace below regardless of the reschedule
+ // predicate, and this test exists to pin the predicate.
+ await new Promise((resolve) => setTimeout(resolve, 600));
+ expect(decoratedBlocks()).toBe(1);
+
+ // A server-side full-body replace whose body bytes are unchanged (e.g. an
+ // agent write that only edits frontmatter) reaches this view as new nodes
+ // carrying equal content: `doc.eq` reads it as "nothing changed", but the
+ // replace's mapping still destroys the node decorations on the range.
+ const state = ed.state;
+ const rebuilt = state.schema.nodeFromJSON(md.parse(BODY));
+ const before = state.doc;
+ ed.view.dispatch(state.tr.replaceWith(0, state.doc.content.size, rebuilt.content));
+ expect(ed.state.doc.eq(before)).toBe(true);
+ expect(ed.state.doc).not.toBe(before);
+ expect(decoratedBlocks()).toBe(0);
+
+ // The plugin must notice the step-bearing transaction and repaint from
+ // source; under a content-equality reschedule predicate the squiggle
+ // stays orphaned forever.
+ await vi.waitFor(() => expect(decoratedBlocks()).toBe(1), { timeout: 5_000 });
+ });
+});
diff --git a/packages/app/src/editor/extensions/markdown-lint-decorations.ts b/packages/app/src/editor/extensions/markdown-lint-decorations.ts
index c2ad28243..73e989685 100644
--- a/packages/app/src/editor/extensions/markdown-lint-decorations.ts
+++ b/packages/app/src/editor/extensions/markdown-lint-decorations.ts
@@ -622,7 +622,18 @@ export const MarkdownLintDecorations = Extension.create<MarkdownLintDecorationsO
return {
update(updatedView, prevState) {
- if (!updatedView.state.doc.eq(prevState.doc)) schedule();
+ // Identity, not `.eq`: a server-side full-body replace whose body
+ // bytes are unchanged (e.g. an agent write that only edits
+ // frontmatter) can reach this view as a content-EQUAL rebuild —
+ // new top-level nodes carrying the same text. Its mapping still
+ // destroys the node decorations on the replaced ranges, but
+ // `.eq` compares content and reads the transaction as "no doc
+ // change", so nothing reschedules and the decorations stay gone
+ // until an unrelated edit. Doc identity changes exactly when a
+ // transaction carried real steps (meta-only dispatches — ours
+ // included — keep the same doc object), so this predicate is
+ // step-sensitive without self-looping on the decoration dispatch.
+ if (updatedView.state.doc !== prevState.doc) schedule();
},
destroy() {
destroyed = true;