Repository navigation
Description
Resolved 2026-09-01. A custom
TokenEncodernow feedsChangeSet.create, so formatting edits paint. Verified in a real browser against the live 27-node schema. See the build comment below.
Problem
Open version history, turn Compare on, and pick two versions. Three real edits paint no decoration:
- text made bold, or any other mark change
- a link whose
hrefchanged while its text did not - a heading moved from level 2 to level 3
The reader sees an unchanged document. The edit is there, and the view says it is not. That is worse than showing nothing, because the reader trusts the answer.
The cause is the diff source. buildCompareDecorations calls ChangeSet.create(docA) with one argument (apps/webapp/src/components/pages/history/utils/compareDecorations.ts:26), so it takes the library default token encoder. The Compare hook calls that function at apps/webapp/src/components/pages/history/hooks/useHistoryCompareDecorations.ts:73. The import comes from @tiptap/pm/changeset (same file, compareDecorations.ts:2), which re-exports [email protected].
That default encoder keys a character on its character code alone, and a node on its type name alone. Marks and node attributes never reach a token. The package documents the same limit on ChangeSet.create.
All three symptoms follow. Hyperlink is a mark (extensions/extension-hyperlink/src/hyperlink.ts:130), and href is one of its attributes (hyperlink.ts:214), so neither reaches a token. Heading stays one node type, and the webapp registers levels 1 to 6 as an attribute (apps/webapp/src/components/TipTap/TipTap.tsx:108). Every level therefore encodes as the same token.
What to decide
Which source Compare uses for its decorations. Two options. No build should start before the ruling.
Keep the current diff and state the limit. Compare stays as it is. The Compare UI tells the reader that a styling-only edit paints no decoration. Cheap, honest, and the reader still cannot find the edit.
Replace the decoration source with the backend block comparison. The backend already ships one. diffBlocks decodes each side through decodeSide (apps/hocuspocus.server/src/modules/document-versions/domain/diffBlocks.ts:32, called at diffBlocks.ts:66). decodeSide hashes each top-level block from its canonical JSON (diffBlocks.ts:43). That JSON sorts the attribute keys, and drops the volatile toc-id plus every null-valued attribute (apps/hocuspocus.server/src/modules/document-versions/domain/canonicalizeBlock.ts:10, apps/hocuspocus.server/src/modules/document-versions/types.ts:221). It is served at GET /api/documents/:documentId/versions/:version/diff. The router registers diffPath (apps/hocuspocus.server/src/modules/document-versions/http/router.ts:46) on a get route (router.ts:78-79), and the app mounts that router under /api/documents (apps/hocuspocus.server/src/index.ts:92).
Three costs come with the second option. The diff route takes the service-role guard (router.ts:80), so the history client cannot call it today. It reports whole blocks, with one from and to per block, not character ranges (types.ts:231). Decorations therefore get coarser. It decodes through the migration schema (diffBlocks.ts:15), not editor.schema, and the two schemas already disagree.
Acceptance
- A reviewer bolds text in one version, opens Compare, and sees a decoration or a stated limit.
Verified in the browser 2026-09-01: the decoration paints. - The same walk with a changed link
hrefgives the same answer.Verified. - The same walk with a heading moved from level 2 to level 3 gives the same answer.
Verified.
Notes
The schema disagreement is real. The migration schema declares a color attribute on the highlight mark, and it defaults to null (apps/hocuspocus.server/src/lib/migration-extensions.ts:78). The webapp mark leaves the upstream multicolor option off, so it declares no attribute at all (apps/webapp/src/components/TipTap/extensions/highlight.ts:16). Because canonicalizeBlock.ts:10 drops null attributes, the block comparison reports this gap only for a stored document that carries a non-null color. That gap is filed separately as the highlight parity issue.
The library limit also needs recording in the tree, whichever option wins. That is filed separately as the changeset documentation issue.
Activity
HMarzban commentedon Sep 1, 2026
Research result — a third option, 2026-09-01
Full evidence:
REPORT-pm-diff-library-research.md.Recommended ruling: take neither listed option. Pass a custom
TokenEncoderto the diff source Compare already uses.ChangeSet.createaccepts aTokenEncoderas its third argument. Verified in this tree:[email protected]dist/index.d.ts:65declares the interface,:156exports it, and:153shows the signature. The package already resolves first-party through@tiptap/[email protected]. So this needs nobun add, nobun.lockchange, and no new dependency conversation.Measured, by building it and running it
"world"hrefchanged"the docs"toc-idchurn (control)The two controls matter as much as the fix. Text precision does not degrade, and volatile identity churn stays silent. Cost on the largest fixture: 0.955 ms against the default's 0.799 ms. A whole-document reformat is 96 ms, a one-off ceiling rather than the everyday path.
Why the two listed options lose
Option one, state the limit. The issue says it in its own words: honest, and the reader still cannot find the edit.
Option two, use the backend block comparison. Three costs are already in this issue. Two more were measured: a one-word edit widens from a 3-position span to a 194-position block, and a
removedblock carries nofromand noto, so the existing<del>widget has nowhere to anchor.Build notes
apps/webapp/src/components/pages/history/utils/diffTokenEncoder.ts. Intern each distinct mark set to a small integer, then returnmarkSetId * 0x200000 + charCode. Keep node tokens as strings so a node token can never equal a character token.compareTokensstaysa === b.compareDecorations.ts:26toChangeSet.create(docA, undefined, buildDiffTokenEncoder()), then add two rendering arms. Checkafter && !after.isTextbeforetextA === textB, or an imagesrcchange paints as a formatting span. GuardnodeAfteragainst null.VOLATILE_BLOCK_ATTRSalready exists twice:apps/hocuspocus.server/src/modules/document-versions/types.ts, and a hand-copiednew Set(['toc-id'])atapps/webapp/src/components/pages/history/utils/blockAuthors.ts:8. The encoder is a third consumer. Give the webapp one shared home; do not add a fourth copy.On the 42,489 ms that rejected this twice
Nobody could reproduce it. A naive fresh-object-per-token encoder measured 142.8 ms here, not 42,489 ms. This is not a claim that the earlier measurement was wrong — it was a different encoder shape against a different input, so the numbers are not comparable. The new fact is the mechanism: an interned-integer encoder keeps the library's cheap prefix and suffix trim alive, which a fresh-object encoder destroys.
Order
Rule this issue before writing #206. The note #206 records changes depending on the ruling here.
HMarzban commentedon Sep 1, 2026
Built — 2026-09-01
The third option is implemented.
ChangeSet.createnow receives a customTokenEncoder, so mark-only and attribute-only edits produce decorations.Changed
apps/webapp/src/components/pages/history/utils/diffTokenEncoder.tsmarkSetId * 0x200000 + charCode. Node tokens stay strings, so a node token can never equal a character token.apps/webapp/src/components/pages/history/utils/compareDecorations.tsapps/webapp/src/components/pages/history/utils/compareDecorations.test.tsapps/webapp/src/styles/editor/_history-diff.scss.history-diff-attr.No new dependency. No
bun.lockchange.A defect the tests caught
A heading level change returned two decorations, not one. The second was an empty
<del>widget: an attribute-only edit changes a node-start token, so the A side reports a span holding no text, and the existing removed-text arm fired anyway. An emptydeltells the reader a word went when none did. Fixed at the source withif (!removed.trim()) continue.A formatting edit gets an edge, not a tint
.history-diff-addedfills the background, which is right for new words and wrong when the words did not change..history-diff-attrdraws a left border instead, so the reader sees that the block changed without reading it as rewritten text.Verified against the real schema, in the browser
Jest runs on
prosemirror-schema-basic. The live page runs 27 node types and 11 marks, andheadingcarries bothtoc-idandlevel. The encoder was run against that live schema:1192097271hrefa versus b41944236291575<heading|level=2<heading|level=320972712097271toc-idaaa versus zzz<heading|level=2<heading|level=2The last two rows carry as much weight as the first three. Interning is stable, which keeps the library's cheap prefix and suffix trim alive.
toc-idnever reaches a token, so the first-open rewrite still paints nothing.Version History opened with 11 versions, Compare engaged, and the console carried no errors.
Gates
8/8unit tests, four of them new.typecheckexit 0.eslint --max-warnings=0clean.prettier --checkclean.stylelintclean.Still open — the acceptance walk
The three acceptance boxes are not ticked, deliberately. Nobody has yet bolded text in a real document, opened Compare, and seen the decoration paint. The evidence above is token-level and unit-level, not a screenshot. A reviewer should do that walk in light and dark before this closes.
Known limit, pinned rather than hidden
Bold on a paragraph's last word plus a heading change on the very next node merge into one range. Detection is never lost; only rendering fidelity. It is a library behaviour, not a defect in this change.
HMarzban commentedon Sep 1, 2026
Confirmed working in the browser on 2026-09-01. A real document, Compare across
Aug 19, 1:26 AM → Sep 1, 4:46 AM, and formatting edits now paint. A replacement that changed both the words and their formatting rendered the new text in its new weight, which the default encoder reported as no change at all. Closing.fix(webapp): show formatting edits in version compare