Skip to content

Record the changeset diff blindness to marks and attributes #206

Closed

Description

@HMarzban

Problem

Version compare diffs two documents with prosemirror-changeset, reached through @tiptap/pm/changeset. The import sits at apps/webapp/src/components/pages/history/utils/compareDecorations.ts:2.

That library's default token encoder compares nodes by name and text by character. It ignores marks and attributes. [email protected] says so in its own ChangeSet.create documentation. The text reads: "The default is to just compare nodes by name and text by character, ignoring marks and attributes." The default encoder's encodeNodeStart is node => node.type.name.

Nothing in this tree records that limit. compareDecorations.ts carries two comments and neither names it. The JSDoc at lines 7-11 says the function diffs two version documents for the read-only history editor, and explains why the code skips .check(). The comment at lines 39-40 explains why removed text uses textBetween instead of a serialized slice.

apps/hocuspocus.server/docs/change-attribution.md is the tracked document that explains what a version diff does and does not prove. It never mentions the library: grep -c -i changeset on that file returns 0.

So the tree reads as an endorsement. The next person who builds on this diff repeats the mistake.

What to do

Write the limit into apps/hocuspocus.server/docs/change-attribution.md. Name the edits the default encoder cannot see.

Add a short why-comment at the import in compareDecorations.ts.

Acceptance

  • grep -c -i changeset apps/hocuspocus.server/docs/change-attribution.md returns a number above 0. Returns 5.
  • That document names marks and attributes as edits the default encoder cannot see. Quoted from the library's own documentation.
  • compareDecorations.ts carries a comment at the import saying the same thing. Three lines above the import.

Notes

The library does hand marks to the encoder. Its internal tokens helper calls encodeCharacter(charCode, marks), and the default encoder drops that second argument. A custom encoder is therefore possible. That is a build choice, not this issue.

The product effect of the same limit is filed separately as the Compare decoration issue. A ruling there may move which surface carries the note. The library fact is worth recording either way.

Activity

  1. added
    documentation
    Editor
    on Aug 31, 2026
  2. HMarzban commented on Sep 1, 2026

    @HMarzban
    CollaboratorAuthor

    Research result — two facts to add, and an ordering note, 2026-09-01

    Full evidence: REPORT-pm-diff-library-research.md.

    The three acceptance greps are unchanged. Nothing in this research widens the scope of this issue.

    Add these two facts to the tracked note

    1. The exact escape hatch, with its version. ChangeSet.create takes a TokenEncoder as its third argument, added in [email protected]. Verified in this tree: dist/index.d.ts:65 declares interface TokenEncoder<T>, :156 exports it, and :153 is static create<Data = any>(doc: Node, combine?: ..., tokenEncoder?: TokenEncoder<any>): ChangeSet<Data>. This turns the note from "a limit we live with" into "a limit with a documented door".

    2. The upgrade hazard, which explains why the pin matters. apps/webapp/node_modules/@tiptap/pm/package.json:184 declares "prosemirror-changeset": "^2.3.0". Only bun.lock:3388 pins 2.3.1. A lockfile refresh could therefore move this package without any deliberate decision.

    Ordering — this issue should be written second

    #207 now has a recommended ruling: pass a custom encoder rather than accept the limit. If that ruling lands, the sentence this issue records changes.

    Rule #207 first, then write this. Otherwise the tracked note documents a limit that no longer exists.

  3. HMarzban commented on Sep 1, 2026

    @HMarzban
    CollaboratorAuthor

    Unblocked — 2026-09-01

    #207 is now built, not just ruled. The compare view passes a custom TokenEncoder, so mark-only and attribute-only edits produce decorations.

    So the sentence this issue records is settled. Write:

    The default token encoder compares nodes by name and text by character, and ignores marks and attributes. This tree therefore passes its own encoder — see apps/webapp/src/components/pages/history/utils/diffTokenEncoder.ts.

    Rather than the limit-we-live-with wording that would have been correct yesterday.

    The three acceptance greps are unchanged. Add the two facts already filed above: the TokenEncoder third argument added in [email protected], and the upgrade hazard where @tiptap/pm declares ^2.3.0 while only bun.lock:3388 pins 2.3.1.

    This issue is ready to write.

  4. HMarzban commented on Sep 1, 2026

    @HMarzban
    CollaboratorAuthor

    Done — 2026-09-01

    Two edits, no behaviour change.

    apps/hocuspocus.server/docs/change-attribution.md gained a ## What the diff engine sees section, placed before ## Failure mode. It sits there rather than inside the authorship sections because it is a limit in the layer above, not a property of the clientID binding.

    It records four things:

    • The library default, quoted: "The default is to just compare nodes by name and text by character, ignoring marks and attributes."
    • The three edits that go unseen under it, in plain words.
    • That this tree passes its own encoder, naming diffTokenEncoder.ts and the [email protected] third argument.
    • Two facts for whoever changes that file next. Interning to integers is not a style choice — it keeps the library's cheap prefix and suffix trim alive, which a fresh object per character destroys. And @tiptap/pm declares ^2.3.0, so only the lockfile pins the version carrying the third argument.

    It closes by noting that the backend block comparison never had this blindness, because canonicalizeBlock hashes whole-block JSON including marks and attributes, at block granularity rather than character range.

    compareDecorations.ts carries a three-line comment above the @tiptap/pm/changeset import, opening with "Never call ChangeSet.create with one argument" and pointing at the document.

    Gates

    8/8 unit tests. typecheck exit 0. eslint --max-warnings=0 clean. prettier --check clean.

    A note on the acceptance greps

    The first grep passes as written. The second and third are line-based, and both phrases wrap across lines in the shipped text — the comment also carries a // between the wrapped words. Checked with whitespace flattened and comment markers stripped, all three pass. Worth knowing before anyone re-runs them literally and reads a false failure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Editordocumentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions