diff --git a/apps/console/scripts/esbuild.mjs b/apps/console/scripts/esbuild.mjs index 93699a94c..15448b71d 100644 --- a/apps/console/scripts/esbuild.mjs +++ b/apps/console/scripts/esbuild.mjs @@ -61,26 +61,29 @@ const hotReloading = { build.initialOptions.banner = build.initialOptions.banner || {}; build.initialOptions.banner.js = ` ${build.initialOptions.banner.js || ""}; - - new EventSource('/esbuild').addEventListener('change', e => { - const { added, removed, updated } = JSON.parse(e.data); - - if (!added.length && !removed.length && updated.length === 1) { - for (const link of document.getElementsByTagName("link")) { - const url = new URL(link.href); - - if (url.host === location.host && url.pathname === updated[0]) { - const next = link.cloneNode(); - next.href = updated[0] + '?' + Math.random().toString(36).slice(2); - next.onload = () => link.remove(); - link.parentNode.insertBefore(next, link.nextSibling); - return; + + if (!window.__esbuild_event_source__) { + window.__esbuild_event_source__ = true; + new EventSource('/esbuild').addEventListener('change', (e) => { + const { added, removed, updated } = JSON.parse(e.data); + + if (!added.length && !removed.length && updated.length === 1) { + for (const link of document.getElementsByTagName("link")) { + const url = new URL(link.href); + + if (url.host === location.host && url.pathname === updated[0]) { + const next = link.cloneNode(); + next.href = updated[0] + '?' + Math.random().toString(36).slice(2); + next.onload = () => link.remove(); + link.parentNode.insertBefore(next, link.nextSibling); + return; + } } } - } - - location.reload(); - }); + + location.reload(); + }); + } `; return; },