Brixus courses are written in a rich-text editor built on Tiptap, the ProseMirror-based framework. Besides the usual paragraphs and lists, a page holds our own nodes: callouts, diagrams, audio clips, dialogues, and about a dozen question types, from multiple choice to fill-in-the-blank.
That document is touched by three runtimes:
- The Angular frontend , where authors edit and learners read.
- A Node.js collaboration server running Hocuspocus, which syncs edits between authors in real time through Yjs and stores the result.
- A .NET backend , which persists pages, and whose AI pipeline generates whole pages as structured JSON.
All three have to agree, exactly, on what a valid document is. This post is about how we keep them in sync, and the test that makes drift impossible to miss.
Why drift loses data silently
Every edit in a collaborative session goes through the collab server. It converts the shared Yjs document back into ProseMirror JSON before storing it, and that conversion runs through the server's schema, not the browser's.
So if the frontend knows a node or an attribute that the server doesn't, nothing crashes. The server builds a document from its own schema, the unknown piece doesn't fit, and it simply isn't there when the page is saved. An author adds a new question type, it looks perfect in their browser, and on reload it's gone.
That class of bug is the worst kind: no error, no stack trace, and it only shows up after content is lost.
Rule 1: declare every custom node once
Custom nodes live in one shared workspace package, @brixus/tiptap-shared, which both the frontend and the collab server import. Each node is a plain Tiptap Node.create({...}): name, group, content expression, attributes, and how it parses from and renders to HTML. It is pure TypeScript with no Angular and no Node APIs at module level, so the same file bundles into a browser build and runs in a Node process.
The frontend adds only what is browser-specific:
import { MultipleChoiceQuestionNode } from '@brixus/tiptap-shared';
export const MultipleChoiceExtension = MultipleChoiceQuestionNode.extend({
addNodeView() {
return AngularNodeViewRenderer(MultipleChoiceComponent);
},
});
The wrapper never redeclares the name, the attributes or the content expression. Those exist in exactly one place.
Standard Tiptap extensions (StarterKit, tables, task lists) are not wrapped. Both sides import them straight from @tiptap/* with the same configuration, and the workspace pins one version of @tiptap/core and @tiptap/pm for everyone.
Rule 2: fingerprint the schema and test both sides against it
Sharing the source isn't enough. Someone can still register a node in the frontend's extension list and forget the server's, or configure StarterKit differently in one place. So we test the result : the compiled ProseMirror schema.
schemaFingerprint(schema) turns a schema into deterministic text. One line per node and mark, sorted by name, with everything that affects what a document may contain:
export function schemaFingerprint(schema: Schema): string {
const lines: string[] = [];
for (const name of Object.keys(schema.nodes).sort()) {
const node = schema.nodes[name];
const attrs = Object.keys(node.spec.attrs ?? {})
.sort()
.map((attr) => `${attr}=${JSON.stringify(node.spec.attrs![attr].default ?? null)}`)
.join(',');
lines.push(
`node ${name} content=${node.spec.content ?? ''} group=${node.spec.group ?? ''}` +
` inline=${node.isInline} atom=${node.isAtom} attrs={${attrs}}`
);
}
// marks are fingerprinted the same way
return lines.join('\n');
}
A line of the output looks like this:
node audio content= group=block inline=false atom=true marks=_ attrs={lang="",showTranscript=true,src="",title="",transcript=""}
The agreed fingerprint is committed as a constant in the shared package. Then both consumers assert against it in their own test suites: the collab server's tests build its schema and compare, and the frontend's tests build the editor's schema and compare. When either side differs, the failure prints the lines that are missing or unexpected, plus the new fingerprint to paste in if the change was intentional.
The effect is that a schema change has to be made on purpose, in one reviewable diff: the node, the expected fingerprint, and both consumers' tests going green together. Forgetting one side fails CI instead of eating content.
Rule 3: the backend gets typed records, pinned by its own test
The .NET backend doesn't run ProseMirror, but it can't treat page JSON as an opaque blob either. The AI pipeline asks a model for page content using strict structured output, so the backend needs a precise JSON schema of every node a page may contain.
Each node that can be generated or stored has a C# record in a shared ContentNodes library, with a type discriminator that serialises as the node's type. The structured-output JSON schema is generated from those records, and a golden test pins it byte for byte. Adding a node therefore touches three places, and each has a test that notices if you skip it.
What it costs, and what it buys
The cost is ceremony. A new node means a shared spec, a frontend wrapper, a server registration, a C# record, and a regenerated fingerprint. We wrote the steps down as a checklist so nobody has to rediscover them.
What it buys is that the most dangerous bug in a collaborative editor, content that silently disappears, can't reach production through a schema mismatch. In a product where every page holds hand-checked exam questions, that trade is easy.
See it running. Every Brixus course is built in this editor, with exam questions inside the lessons. The first lesson of each course is free to read, no account needed. Read a free lesson
Top comments (0)