From 70e4bcb6bdba193ef93ca67d12e652cd7f458e44 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Wed, 4 Nov 2026 07:02:44 +0000 Subject: [PATCH] fix(website): canonicalize mermaid export colour tokens in the demo's export key Since 0.44.0, staticMermaidSvg names its colour tokens after the render's brain-mermaid id (--bk-mermaid---). The demo's export key normalized only the id, so once the Files viewer had drawn a diagram on screen, sharing it as an image rendered as brain-mermaid-2 and hashed to a key the prepared catalogue does not have. The demo answered 422 and no download started, which failed every publication run's rich-demo check. Canonicalize the token's render number the same way as the id; its pass and index, and all content and styling, stay in the digest. Co-Authored-By: Claude Opus 5.5 --- website/src/demo/export-key.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/website/src/demo/export-key.ts b/website/src/demo/export-key.ts index 7e2535b9af..a10d754ad7 100644 --- a/website/src/demo/export-key.ts +++ b/website/src/demo/export-key.ts @@ -1,10 +1,13 @@ import type { RenderRequest } from '@schlessera/brain-ui-sdk/protocol'; -// Mermaid's monotonically numbered DOM IDs change with browsing order. Only -// those IDs and their references are canonicalized; content and styling remain -// part of the digest. Never substitute a vaguely similar document on a miss. +// Mermaid's monotonically numbered DOM IDs change with browsing order, and so +// do the static-export colour tokens named after them (`--bk-mermaid--…`, +// `staticMermaidSvg`). Only that render number is canonicalized; the token's +// pass and index, the content and the styling remain part of the digest. +// Never substitute a vaguely similar document on a miss. export function canonicalExport(request: RenderRequest) { - return JSON.stringify({ contentType: request.contentType, title: request.title || '', content: request.content.replace(/brain-mermaid-\d+/g, 'brain-mermaid-export') }); + const content = request.content.replace(/brain-mermaid-\d+/g, 'brain-mermaid-export').replace(/--bk-mermaid-\d+-/g, '--bk-mermaid-export-'); + return JSON.stringify({ contentType: request.contentType, title: request.title || '', content }); } export async function exportKey(request: RenderRequest) { const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonicalExport(request)));