A mermaid extension for odoc
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix SPA init: poll for CDN scripts from initial load, not just observer

The MutationObserver only fires on future mutations. When the init
script loads after content swap (SPA), the content is already in the
DOM and no mutations will fire. Start polling for the CDN library
immediately from init(), not just from the observer callback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

+14 -6
+14 -6
src/mermaid_extension.ml
··· 248 248 try { mermaid.run({ nodes: Array.from(pending) }); } catch(e) { console.error('mermaid.run error:', e); } 249 249 } 250 250 251 - if (document.readyState === 'loading') { 252 - document.addEventListener('DOMContentLoaded', function() { 253 - renderAll(); 254 - observe(); 255 - }); 256 - } else { 251 + function init() { 257 252 renderAll(); 258 253 observe(); 254 + // If mermaid isn't loaded yet but there are pending elements, 255 + // start polling immediately (handles SPA where this script loads 256 + // after content swap but before CDN script finishes). 257 + if (typeof mermaid === 'undefined' && 258 + document.querySelectorAll('pre.mermaid:not([data-mermaid-init])').length > 0) { 259 + waitForMermaid(); 260 + } 261 + } 262 + 263 + if (document.readyState === 'loading') { 264 + document.addEventListener('DOMContentLoaded', init); 265 + } else { 266 + init(); 259 267 } 260 268 261 269 function observe() {