question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SvelteKit loads favicon every page request and messes up the request

See original GitHub issue

Describe the bug

I think there are two problems here:

  1. favicon.png is request on each navigation (why?)
  2. favicon in dev mode SOMETIMES is not found (404)

I have an API in SvelteKit structured as this Screenshot from 2022-02-06 16-55-57

For some very strange reason SvelteKit tries to load favicon with every request in a very weird way. SK

Moreover when I check the params of the request with values lang: ‘en’ and searched: ‘32015L2366’ I see that there were two requests: The first request:

Request {
  size: 0,
  follow: 20,
  compress: true,
  counter: 0,
  agent: undefined,
  highWaterMark: 16384,
  insecureHTTPParser: false,
  [Symbol(Body internals)]: {
    body: null,
    stream: null,
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Request internals)]: {
    method: 'GET',
    redirect: 'follow',
    headers: {
      accept: 'image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8',
      'accept-encoding': 'gzip, deflate, br',
      'accept-language': 'en-US,en;q=0.9,cs;q=0.8',
      connection: 'keep-alive',
      referer: 'http://localhost:3000/en/favicon.png',
      'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98"',
      'sec-ch-ua-mobile': '?0',
      'sec-ch-ua-platform': '"Linux"',
      'sec-fetch-dest': 'image',
      'sec-fetch-mode': 'no-cors',
      'sec-fetch-site': 'same-origin',
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36'
    },
    parsedURL: URL {
      href: 'http://localhost:3000/api/en/favicon.png.json',
      origin: 'http://localhost:3000',
      protocol: 'http:',
      username: '',
      password: '',
      host: 'localhost:3000',
      hostname: 'localhost',
      port: '3000',
      pathname: '/api/en/favicon.png.json',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    },
    signal: null,
    referrer: undefined,
    referrerPolicy: ''
  }
}

Console logged params are:

{ lang: 'en', searched: 'favicon.png' }

The second request {correct one) is:

Request {
  size: 0,
  follow: 20,
  compress: true,
  counter: 0,
  agent: undefined,
  highWaterMark: 16384,
  insecureHTTPParser: false,
  [Symbol(Body internals)]: {
    body: null,
    stream: null,
    boundary: null,
    disturbed: false,
    error: null
  },
  [Symbol(Request internals)]: {
    method: 'GET',
    redirect: 'follow',
    headers: {
      accept: '*/*',
      'accept-encoding': 'gzip, deflate, br',
      'accept-language': 'en-US,en;q=0.9,cs;q=0.8',
      connection: 'keep-alive',
      host: 'localhost:3000',
      'if-none-match': '"1dyn90w"',
      referer: 'http://localhost:3000/en/32015L2366',
      'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="98"',
      'sec-ch-ua-mobile': '?0',
      'sec-ch-ua-platform': '"Linux"',
      'sec-fetch-dest': 'empty',
      'sec-fetch-mode': 'cors',
      'sec-fetch-site': 'same-origin',
      'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.80 Safari/537.36'
    },
    parsedURL: URL {
      href: 'http://localhost:3000/api/en/32015L2366.json',
      origin: 'http://localhost:3000',
      protocol: 'http:',
      username: '',
      password: '',
      host: 'localhost:3000',
      hostname: 'localhost',
      port: '3000',
      pathname: '/api/en/32015L2366.json',
      search: '',
      searchParams: URLSearchParams {},
      hash: ''
    },
    signal: null,
    referrer: undefined,
    referrerPolicy: ''
  }

Console logged params are:

{ lang: 'en', searched: '32015L2366' }

Looks like a ghost in the shell.

Reproduction

See the structure in the picture above.

Logs

No response

System Info

Pop!_OS 21.10 , Browser info can be seen hereabove.

Severity

serious, but I can work around it

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:10
  • Comments:21 (11 by maintainers)

github_iconTop GitHub Comments

6reactions
fehnomenalcommented, May 13, 2022

I have a similar “problem” (quotes because it does not really break anything but my client wants to get rid of errors in the console).

I noticed that only Chrome/Chromium loads the favicon on each navigation, on Firefox it is fine.

The issue (console errors) happens when the url generated by %svelte.assets% (which is relative) is no longer valid when resolving to the url after navigating. This happens when navigating from / with href="./favicon.png" to /foo/bar. Then the href stays the same but Chromium tries to resolve the favicon from /foo/favicon.png which is obviously incorrect.

Again this does not break anything but is only annoying.

5reactions
rumackcommented, Mar 11, 2022

Sorry, just seeing these last exchanges now. I went back into the three Sveltekit apps where I was getting this error and reinserted %svelte.assets%/favicon.png, after adding trailingSlash: 'always' to svelte.config.js. Error seems to be gone. Using the node adapter. Cheers!

Sorry, I spoke too soon. Error not fixed. I’ve had to remove the %svelte.assets% from app.html again. Otherwise I get 404 errors as it looks for routes that don’t exist - somehow /favicon is appended onto normal routes which then can’t be found…

Read more comments on GitHub >

github_iconTop Results From Across the Web

SvelteKit loads favicon every page request - Stack Overflow
I don't have this issue with favicon. I'm setting favicon in top most __layout.svelte via <svelte:head> like this:
Read more >
Loading data • Docs • SvelteKit
A load function in a +page.js file runs both on the server and in the browser. ... load functions have access to properties...
Read more >
How to prevent multiple API requests : r/sveltejs - Reddit
My goal is load data from an API, then save it into the store. Then, if I navigate to another page and back...
Read more >
Changing Your Favicon in Svelte/SvelteKit - YouTube
Are you trying to get your favorite favicon.ico connected to your latest Svelte project? No problem. This short video will help you do...
Read more >
SvelteKit 1.0 | Hacker News
You can even mix and match from page to page: Server-side render one page per request; statically generate another at build time.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found