Fix too many SSE conn open in dev mode
Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
@@ -62,25 +62,28 @@ const hotReloading = {
|
|||||||
build.initialOptions.banner.js = `
|
build.initialOptions.banner.js = `
|
||||||
${build.initialOptions.banner.js || ""};
|
${build.initialOptions.banner.js || ""};
|
||||||
|
|
||||||
new EventSource('/esbuild').addEventListener('change', e => {
|
if (!window.__esbuild_event_source__) {
|
||||||
const { added, removed, updated } = JSON.parse(e.data);
|
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) {
|
if (!added.length && !removed.length && updated.length === 1) {
|
||||||
for (const link of document.getElementsByTagName("link")) {
|
for (const link of document.getElementsByTagName("link")) {
|
||||||
const url = new URL(link.href);
|
const url = new URL(link.href);
|
||||||
|
|
||||||
if (url.host === location.host && url.pathname === updated[0]) {
|
if (url.host === location.host && url.pathname === updated[0]) {
|
||||||
const next = link.cloneNode();
|
const next = link.cloneNode();
|
||||||
next.href = updated[0] + '?' + Math.random().toString(36).slice(2);
|
next.href = updated[0] + '?' + Math.random().toString(36).slice(2);
|
||||||
next.onload = () => link.remove();
|
next.onload = () => link.remove();
|
||||||
link.parentNode.insertBefore(next, link.nextSibling);
|
link.parentNode.insertBefore(next, link.nextSibling);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
location.reload();
|
location.reload();
|
||||||
});
|
});
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user