Fix too many SSE conn open in dev mode
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user