Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore requests to /_favicon/ #819

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-oranges-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@crxjs/vite-plugin": patch
---

fix: ignore requests to /_favicon/
9 changes: 9 additions & 0 deletions packages/vite-plugin/src/client/es/hmr-client-worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ self.addEventListener('fetch', (fetchEvent) => {
* https://bugs.chromium.org/p/chromium/issues/detail?id=1247690#c_ts1631117342
*/
async function sendToServer(url: URL): Promise<Response> {
if (url.href.includes('/_favicon/')) {
const response = await fetch(url.href)
return new Response(response.body, {
headers: {
'Content-Type': response.headers.get('Content-Type') ?? 'text/javascript',
},
})
}
Copy link
Contributor

@jacksteamdev jacksteamdev Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I imagine there are other use cases to not redirect to the dev server, so I think it's best if we handle all this in one place. What if we move url.href.includes('/_favicon/') up into line 23 and abstract it into a guard function?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I put them in a array const ignoreURLPaths = ['/_favicon/'], in case there are other paths to ignore as well (also perhaps allow users to add their own ignore paths). It's not as efficient as doing separate if statements as before (though V8 is probably optimizing these on its own), but as I mentioned in the future users might want to add other ignore paths?


// change the url to point to the dev server
url.protocol = 'http:'
url.host = 'localhost'
Expand Down
Loading