1// Defensive guard for rare Bootstrap modal race conditions in SPA navigation. 2// In Blazor, the DOM can be replaced while a Bootstrap modal transition callback is still running. 3// This can surface as "Cannot read properties of null (reading 'style')" from modal.js/_hideModal. 4 5(function () { 6 function looksLikeBootstrapModalHideNullStyle(err) { 7 const msg = (err && (err.message || err.toString())) || ''; 8 if (!msg) return false; 9 10 // Match common variants across browsers/bundles. 11 return ( 12 msg.includes("Cannot read properties of null") && msg.includes("style") && (msg.includes("modal") || msg.includes("_hideModal")) 13 ) || ( 14 msg.includes("Cannot read property 'style' of null") && (msg.includes("modal") || msg.includes("_hideModal")) 15 ); 16 } 17 18 function safeCleanupArtifacts() { 19 try { 20 if (window.bootstrapModalCleanup && typeof window.bootstrapModalCleanup.cleanupModalArtifacts === 'function') { 21 window.bootstrapModalCleanup.cleanupModalArtifacts(); 22 } 23 } catch { 24 // ignore 25 } 26 } 27 28 window.addEventListener('error', (e) => { 29 const err = e?.error || e; 30 if (!looksLikeBootstrapModalHideNullStyle(err)) { 31 return; 32 } 33 34 // Prevent the error from surfacing as an unhandled exception. 35 try { e.preventDefault?.(); } catch { /* ignore */ } 36 37 // Best-effort cleanup so the UI isn't left stuck. 38 safeCleanupArtifacts(); 39 }); 40 41 window.addEventListener('unhandledrejection', (e) => { 42 const err = e?.reason; 43 if (!looksLikeBootstrapModalHideNullStyle(err)) { 44 return; 45 } 46 47 try { e.preventDefault?.(); } catch { /* ignore */ } 48 safeCleanupArtifacts(); 49 }); 50})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.