<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Brixus.eu</title>
    <description>The latest articles on DEV Community by Brixus.eu (@brixus).</description>
    <link>https://dev.to/brixus</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4233448%2F7c92f54d-734b-4a93-8535-c7e2ceb57218.png</url>
      <title>DEV Community: Brixus.eu</title>
      <link>https://dev.to/brixus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/brixus"/>
    <language>en</language>
    <item>
      <title>Why Our Collaborative Editor Doubled Pages on Reconnect</title>
      <dc:creator>Brixus.eu</dc:creator>
      <pubDate>Thu, 26 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/brixus/why-our-collaborative-editor-doubled-pages-on-reconnect-45d9</link>
      <guid>https://dev.to/brixus/why-our-collaborative-editor-doubled-pages-on-reconnect-45d9</guid>
      <description>&lt;p&gt;Brixus authors edit course pages together in real time. The editor is &lt;a href="https://tiptap.dev" rel="noopener noreferrer"&gt;Tiptap&lt;/a&gt; in an Angular app, synced through &lt;a href="https://yjs.dev" rel="noopener noreferrer"&gt;Yjs&lt;/a&gt; by a &lt;a href="https://tiptap.dev/docs/hocuspocus" rel="noopener noreferrer"&gt;Hocuspocus&lt;/a&gt; server, with the page stored as ProseMirror JSON in our .NET backend.&lt;/p&gt;

&lt;p&gt;For a while we had a bug that sounds impossible: occasionally an author reconnected and every paragraph, every question and every image on the page appeared &lt;strong&gt;twice&lt;/strong&gt;. Nobody had pasted anything. The page had simply doubled.&lt;/p&gt;

&lt;p&gt;Here is why it happened, and the small change that made it impossible.&lt;/p&gt;

&lt;h2&gt;
  
  
  How the pieces fit together
&lt;/h2&gt;

&lt;p&gt;When an author opens a page, the collab server loads it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Fetch the page's ProseMirror JSON from the backend.&lt;/li&gt;
&lt;li&gt;Build a Yjs document from it with &lt;code&gt;prosemirrorJSONToYDoc&lt;/code&gt; from &lt;code&gt;y-prosemirror&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Sync that document to every connected browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;While people edit, the server converts the Yjs document back to JSON with &lt;code&gt;yDocToProsemirrorJSON&lt;/code&gt; and stores it. When the last author leaves, the document is unloaded from memory. The next person to open the page starts again at step 1.&lt;/p&gt;

&lt;p&gt;This all looks reasonable, and it is fine almost all the time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the page doubled
&lt;/h2&gt;

&lt;p&gt;Yjs is a CRDT. Every piece of content in a Yjs document is an item with an identity: the id of the client that created it plus a counter. Merging two copies of a document means taking the union of their items, and items with the same id are the same item. That's what makes merging safe and repeatable.&lt;/p&gt;

&lt;p&gt;The problem is step 2. Building a Yjs document &lt;strong&gt;from JSON&lt;/strong&gt; creates every item fresh, under a new random client id. The content is identical, but as far as Yjs is concerned it is all new content that has never been seen before.&lt;/p&gt;

&lt;p&gt;Now picture this sequence:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;An author has a page open. Their browser holds the Yjs document, with item ids from the server's last build.&lt;/li&gt;
&lt;li&gt;The server unloads that document. This happens on a deploy, a restart, or simply because the connection dropped long enough that the server saw nobody connected.&lt;/li&gt;
&lt;li&gt;The author's tab is still open. It reconnects.&lt;/li&gt;
&lt;li&gt;The server rebuilds the document from JSON, which means &lt;strong&gt;new ids for the same content&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;The browser and the server sync. Yjs sees two independent histories, each containing a full copy of the page, and merges them the only way it can: it keeps both.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The page doubles, and the doubled version is then stored as if someone had written it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix: persist the Yjs state, not just the JSON
&lt;/h2&gt;

&lt;p&gt;The cure is to make the server rebuild the &lt;em&gt;same&lt;/em&gt; document, with the same ids, after an unload. Yjs can serialise a document's complete state as a binary update with &lt;code&gt;Y.encodeStateAsUpdate&lt;/code&gt;. So every time the server stores a page, it now sends both:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the ProseMirror JSON, which the rest of the backend reads, and&lt;/li&gt;
&lt;li&gt;the encoded Yjs state, stored next to it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On load, the server prefers the state:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;resolveInitialUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;docJson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;byteLength&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nf"&gt;stateMatchesJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;docJson&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'state'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;jsonToUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;docJson&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'json'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restoring from the state brings back the original item ids. When the author's tab reconnects, Yjs recognises every item it already has, and the merge changes nothing. Merging is idempotent again.&lt;/p&gt;

&lt;h2&gt;
  
  
  The guard: only trust state that still matches the JSON
&lt;/h2&gt;

&lt;p&gt;There is one catch. Not every write to a page goes through the collab server. Our AI pipeline generates pages, and maintenance scripts that copy or regenerate books write content directly. After any of those, the stored Yjs state describes an &lt;strong&gt;older&lt;/strong&gt; version of the page than the JSON does. Restoring it would silently roll back the newer content.&lt;/p&gt;

&lt;p&gt;So the state is trusted only if it still describes the stored JSON:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;stateMatchesJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;docJson&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;unknown&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;boolean&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;restored&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="no"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Doc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="no"&gt;Y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;applyUpdate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;restored&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;state&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;documentToJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;restored&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="nb"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;normalizeDocumentJSON&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;docJson&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;catch&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;finally&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;restored&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;destroy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both sides are normalised through the same schema first, so attribute defaults and mark order can't cause false mismatches. On top of that, the backend clears the stored state whenever it writes page content outside the collab server, so a stale state is usually gone before the check even runs. If the server ever has to fall back to JSON, it logs a warning, because that is exactly the situation that used to double pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we took away
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;In Yjs, content identity is the item id, not the text.&lt;/strong&gt; Two documents with identical content but different ids are different documents, and merging them duplicates everything.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rebuilding a CRDT document from a plain snapshot is a fork.&lt;/strong&gt; It's safe only if no client still holds the old history. With browser tabs that stay open for hours, some client always does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persist the CRDT state alongside the readable format.&lt;/strong&gt; The JSON stays the source of truth for everything else; the state exists so the collab server can come back as the same document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Guard against stale state.&lt;/strong&gt; Any write that bypasses the CRDT must invalidate its persisted state, and the loader should verify the state before trusting it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The whole fix is a few dozen lines on the server and one extra column in the database. Most of the work was understanding why a merge that is supposed to be safe could duplicate a page at all.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See it running.&lt;/strong&gt; 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. &lt;a href="https://brixus.eu/books/az-900-master-the-basics-of-azure/read/cloud-computing-fundamentals" rel="noopener noreferrer"&gt;Read a free lesson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>yjs</category>
      <category>hocuspocus</category>
      <category>realtimecollaboratio</category>
    </item>
    <item>
      <title>One Editor Schema, Three Runtimes: Tiptap in Angular, Node and .NET</title>
      <dc:creator>Brixus.eu</dc:creator>
      <pubDate>Thu, 19 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/brixus/one-editor-schema-three-runtimes-tiptap-in-angular-node-and-net-3f90</link>
      <guid>https://dev.to/brixus/one-editor-schema-three-runtimes-tiptap-in-angular-node-and-net-3f90</guid>
      <description>&lt;p&gt;Brixus courses are written in a rich-text editor built on &lt;a href="https://tiptap.dev" rel="noopener noreferrer"&gt;Tiptap&lt;/a&gt;, 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.&lt;/p&gt;

&lt;p&gt;That document is touched by three runtimes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Angular frontend&lt;/strong&gt; , where authors edit and learners read.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Node.js collaboration server&lt;/strong&gt; running &lt;a href="https://tiptap.dev/docs/hocuspocus" rel="noopener noreferrer"&gt;Hocuspocus&lt;/a&gt;, which syncs edits between authors in real time through Yjs and stores the result.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A .NET backend&lt;/strong&gt; , which persists pages, and whose AI pipeline generates whole pages as structured JSON.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why drift loses data silently
&lt;/h2&gt;

&lt;p&gt;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 &lt;strong&gt;server's&lt;/strong&gt; schema, not the browser's.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;That class of bug is the worst kind: no error, no stack trace, and it only shows up after content is lost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 1: declare every custom node once
&lt;/h2&gt;

&lt;p&gt;Custom nodes live in one shared workspace package, &lt;code&gt;@brixus/tiptap-shared&lt;/code&gt;, which both the frontend and the collab server import. Each node is a plain Tiptap &lt;code&gt;Node.create({...})&lt;/code&gt;: 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.&lt;/p&gt;

&lt;p&gt;The frontend adds only what is browser-specific:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;MultipleChoiceQuestionNode&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="s1"&gt;'@brixus/tiptap-shared'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nc"&gt;MultipleChoiceExtension&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;MultipleChoiceQuestionNode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nf"&gt;addNodeView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;AngularNodeViewRenderer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;MultipleChoiceComponent&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wrapper never redeclares the name, the attributes or the content expression. Those exist in exactly one place.&lt;/p&gt;

&lt;p&gt;Standard Tiptap extensions (StarterKit, tables, task lists) are not wrapped. Both sides import them straight from &lt;code&gt;@tiptap/*&lt;/code&gt; with the same configuration, and the workspace pins one version of &lt;code&gt;@tiptap/core&lt;/code&gt; and &lt;code&gt;@tiptap/pm&lt;/code&gt; for everyone.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 2: fingerprint the schema and test both sides against it
&lt;/h2&gt;

&lt;p&gt;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 &lt;strong&gt;result&lt;/strong&gt; : the compiled ProseMirror schema.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;schemaFingerprint(schema)&lt;/code&gt; turns a schema into deterministic text. One line per node and mark, sorted by name, with everything that affects what a document may contain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;schemaFingerprint&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;Schema&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;node&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;nodes&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;attrs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;node&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;spec&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;attrs&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attr&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="sb"&gt;`${attr}=${JSON.stringify(node.spec.attrs![attr].default ?? null)}`&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;','&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
      &lt;span class="sb"&gt;`node ${name} content=${node.spec.content ?? ''} group=${node.spec.group ?? ''}`&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
        &lt;span class="sb"&gt;` inline=${node.isInline} atom=${node.isAtom} attrs={${attrs}}`&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// marks are fingerprinted the same way&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'\n'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A line of the output looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node audio content= group=block inline=false atom=true marks=_ attrs={lang="",showTranscript=true,src="",title="",transcript=""}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The agreed fingerprint is committed as a constant in the shared package. Then &lt;strong&gt;both&lt;/strong&gt; 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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rule 3: the backend gets typed records, pinned by its own test
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Each node that can be generated or stored has a C# record in a shared &lt;code&gt;ContentNodes&lt;/code&gt; library, with a type discriminator that serialises as the node's &lt;code&gt;type&lt;/code&gt;. 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.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs, and what it buys
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See it running.&lt;/strong&gt; 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. &lt;a href="https://brixus.eu/books/az-900-master-the-basics-of-azure/read/cloud-computing-fundamentals" rel="noopener noreferrer"&gt;Read a free lesson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>tiptap</category>
      <category>angular</category>
      <category>net</category>
    </item>
    <item>
      <title>Our Google Traffic Didn't Drop. Our Analytics Said It Did.</title>
      <dc:creator>Brixus.eu</dc:creator>
      <pubDate>Thu, 12 Nov 2026 00:00:00 +0000</pubDate>
      <link>https://dev.to/brixus/our-google-traffic-didnt-drop-our-analytics-said-it-did-25d6</link>
      <guid>https://dev.to/brixus/our-google-traffic-didnt-drop-our-analytics-said-it-did-25d6</guid>
      <description>&lt;p&gt;In September we merged our marketing site into the app, so everything moved onto one domain. A few weeks later Google Analytics told a frightening story: organic search visits had fallen off a cliff, right after the move. It looked like the migration had broken our SEO.&lt;/p&gt;

&lt;p&gt;It hadn't. Search traffic was growing the whole time. Our analytics had simply stopped seeing most of it. This is the story of how we found out, and how we count visits now.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the dashboards said
&lt;/h2&gt;

&lt;p&gt;Two tools, two completely different pictures of the same weeks:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Source&lt;/th&gt;
&lt;th&gt;After the move&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Google Analytics 4&lt;/td&gt;
&lt;td&gt;Organic visits dropped to almost nothing&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google Search Console&lt;/td&gt;
&lt;td&gt;Impressions more than doubled; clicks held steady&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Search Console counts clicks on Google's own side, before the visitor ever reaches your site. Nothing in the browser can hide those. So when the two disagree, Search Console is the one to believe for search traffic. That alone told us the "drop" was a measurement problem, not a ranking problem. We checked the rest anyway: no manual action, no indexing errors beyond a sitemap that needed resubmitting, and course pages starting to rank for searches they had never ranked for before.&lt;/p&gt;

&lt;h2&gt;
  
  
  The cause: Consent Mode with a default of "denied"
&lt;/h2&gt;

&lt;p&gt;The old marketing site had no cookie banner and no Consent Mode. The app did. When the two merged, every page on the domain inherited the app's setup: Google's Consent Mode with &lt;code&gt;analytics_storage&lt;/code&gt; set to &lt;code&gt;denied&lt;/code&gt; until the visitor accepts.&lt;/p&gt;

&lt;p&gt;That is the right default under GDPR. But it has a consequence that is easy to miss on a small site:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A visitor who declines, or simply ignores the banner, sends no normal analytics hits.&lt;/li&gt;
&lt;li&gt;Google can fill that gap with &lt;strong&gt;behavioural modelling&lt;/strong&gt; , estimating the missing visitors from the ones who consented. But modelling only switches on once a property has a substantial volume of both consented and unconsented traffic every day, for days in a row.&lt;/li&gt;
&lt;li&gt;A young site is nowhere near that. So the unconsented visitors are not modelled. They are just gone.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Search visitors are exactly the ones least likely to click "Accept" on a site they have never seen. So the people GA4 lost were disproportionately the ones arriving from Google, and the organic channel looked like it had collapsed.&lt;/p&gt;

&lt;h2&gt;
  
  
  How we count visits now
&lt;/h2&gt;

&lt;p&gt;We didn't want a second cookie banner, and we didn't want to guess. So we moved visit counting to the server, where it needs no consent because it stores nothing that identifies a person.&lt;/p&gt;

&lt;p&gt;Every page is served by our Angular SSR server (Express), so it sees every full page load. A small recorder there:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Counts 2xx page loads&lt;/strong&gt; of real pages. Unknown URLs answer 404 and are never counted, so scanners probing &lt;code&gt;/wp-login.php&lt;/code&gt; don't inflate the numbers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tells people from bots&lt;/strong&gt; without cookies. A visitor is identified only by a hash of their IP address and user agent with a salt that changes every day, so the same person is one visitor today and unrecognisable tomorrow. Known crawlers are counted separately. A browser-like client only counts as a person once the page reports a first real interaction (a tap, a key press, a mouse move), because most headless scrapers never send one.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sends aggregate counts&lt;/strong&gt; to the backend once a minute: page, day, landing source, device type. Never the hash, never an address.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Our privacy statement describes exactly what is kept, and nothing in it needed consent. The result is a traffic number we trust, with GA4 kept for what it is good at: detailed behaviour of the visitors who opted in.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Search Console is the ground truth for search traffic.&lt;/strong&gt; Look there first before concluding that a migration hurt your rankings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A Consent Mode change is a measurement change.&lt;/strong&gt; If your consent setup changes, your GA4 history before and after is not comparable, especially below the modelling threshold.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Small sites can't rely on modelling.&lt;/strong&gt; If most of your visitors never accept analytics cookies, GA4 shows you a sample, not your traffic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Count what you need on the server.&lt;/strong&gt; Page loads, landing sources and conversions can be counted without cookies and without identifying anyone. It is less detailed than client-side analytics, and that is the point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The migration was fine all along. The only thing that broke was our view of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;See it running.&lt;/strong&gt; 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. &lt;a href="https://brixus.eu/books/az-900-master-the-basics-of-azure/read/cloud-computing-fundamentals" rel="noopener noreferrer"&gt;Read a free lesson&lt;/a&gt;&lt;/p&gt;

</description>
      <category>analytics</category>
      <category>ga4</category>
      <category>seo</category>
    </item>
  </channel>
</rss>
