QwikDev / qwik

Instant-loading web apps, without effort
https://qwik.dev
MIT License
20.45k stars 1.26k forks source link

[🐞] PrefetchServiceWorker throws `insufficient resources` when navigating while prefetching #6602

Open DustinJSilk opened 1 week ago

DustinJSilk commented 1 week ago

Which component is affected?

Qwik Runtime

Describe the bug

While the PrefetchServiceWorker prefetches the graph, if you interact/navigate to a new page which triggers another prefetch, the browsers throws errors with insufficient resources.

Please see the below video.

https://github.com/QwikDev/qwik/assets/5979984/b38f056e-8baf-48b8-999d-33a63282dfe8

Reproduction

https://github.com/DustinJSilk/qwik-prefetch-nav-crash

Steps to reproduce

$ ./generate.sh

$ pnpm i

$ pnpm preview

Click on the page link before the graph finishes prefetching and see 404s thrown.

System Info

n/a

Additional Information

No response

gioboa commented 1 week ago

How can we solve this issue? @DustinJSilk do you have a possible solution?

DustinJSilk commented 1 week ago

I'm not too clued up on the current implementation, but would this not point to an issue where $maxPrefetchRequests$ isn't being respected, which means the dependencies for the linked page are all being fetched with the highest priority? So the issue here would actually be how the graph is built where all 750 child pages are set as required dependencies for the navigated page to load when they aren't needed yet

gioboa commented 1 week ago

Can you test this version in your environment pls? It works fine for me.

DustinJSilk commented 1 week ago

I'm still getting the same issue mentioned above.

It seems to exist in reverse order as well in a slightly different way, maybe this will help to identify the problem: When first loading the child page, it doesn't prefetch all the symbols yet. Then, when navigating to the home page it prefetches all the symbols in parallel causing the same error as above. I've attached a video below showing this similar issue.

https://github.com/QwikDev/qwik/assets/5979984/d19f32e5-a89f-4327-a129-89c0363dd000

DustinJSilk commented 6 days ago

As I think about it, i wonder if its safe to allow the browser to throw these errors since as long as they eventually recover. We don't know what the limit is per device and don't want to restrict how fast we prefetch if the files are high priority.

So I think the real issue here isn't the fact that the errors are being thrown, they can be ignored, but rather that we're fetching bundles with high priority when they aren't in fact high priority.

gioboa commented 6 days ago

In my PR the dependencies have less priority than the "prefetch" bundles. I think we need to limit the requests in parallel