My aggregated monorepo of OCaml code, automaintained
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>

+25 -12
+11 -6
odoc-dot-extension/src/dot_extension.ml
··· 145 145 }); 146 146 } 147 147 148 + function init() { 149 + renderAll(); 150 + observe(); 151 + if (typeof Viz === 'undefined' && 152 + document.querySelectorAll('.odoc-dot-diagram:not([data-dot-init])').length > 0) { 153 + waitForViz(); 154 + } 155 + } 156 + 148 157 if (document.readyState === 'loading') { 149 - document.addEventListener('DOMContentLoaded', function() { 150 - renderAll(); 151 - observe(); 152 - }); 158 + document.addEventListener('DOMContentLoaded', init); 153 159 } else { 154 - renderAll(); 155 - observe(); 160 + init(); 156 161 } 157 162 158 163 function observe() {
+14 -6
odoc-mermaid-extension/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() {