Skip to content

Commit

Permalink
hot: fix onFetch handler dead loop
Browse files Browse the repository at this point in the history
  • Loading branch information
ije committed Mar 5, 2024
1 parent 91a5600 commit 70e050c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,18 @@ class Hot implements HotCore {
const pathOrHref = isSameOrigin ? pathname : request.url;
const archive = this._archive;
const listeners = this._fetchListeners;
let responded = false;
const respondWith = (res: Response | Promise<Response>) => {
responded = true;
evt.respondWith(res);
};
const respondWith = evt.respondWith.bind(evt);
if (isSameOrigin && pathname.startsWith("/@hot/")) {
respondWith(serveVFS(pathname.slice(6)));
} else if (archive?.exists(pathOrHref)) {
const file = archive.openFile(pathOrHref)!;
respondWith(createResponse(file, { "content-type": file.type }));
} else if (listeners.length > 0) {
evt.respondWith = respondWith;
let responded = false;
evt.respondWith = (res: Response | Promise<Response>) => {
responded = true;
respondWith(res);
};
for (const handler of listeners) {
if (responded) {
break;
Expand Down

0 comments on commit 70e050c

Please sign in to comment.