-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Hooking into asset serving to avoid 404 #12815
Comments
Prevent 404s in what way? What would you return instead? There are built-in mechanisms for dealing with this version skew issue. Have you looked into those and decided they are insufficient? |
By storing old build artifacts in some external storage and fetching it from there in the 404 handler.
From what I know that only applies if you use Vercel to host the site? Or am I missing something? |
When SvelteKit fetches an asset, it will check if the deployed version number has changed. If the version has changed, it performs a full-page reload. |
That's great to hear, but what I encountered was that during our deploy the start page was served from version 1 and then when my browser wanted to request the needed assets those were gone because the instance that got the requests had version 2 and I got a lovely old-school page of unstyled HTML and no scripts. |
Can you confirm if this is the same issue as #9089 ? Otherwise, we need a minimal reproduction to further diagnose this as a separate issue. |
It's hard to say, feels like there's a lot of people with slightly different cases in that thread, but it's certainly very similar.
You can either delete random files in The only thing I can think of to repair it is to fallback on an external storage of old build artifacts, and to implement that I'd need to be able to hook into the 404 handling. |
Can you provide a repository and list the expected and actual outcomes? |
Maybe, but the only way SvelteKit could handle this situation would be to add I don't expect SvelteKit to solve this for me and it's a bit of an edge case, but does happen in real-life if you have enough traffic during deploy time. Which is why I was asking for the hook so I could solve it in userland. |
This sounds like something a service worker would be useful for doing (if I'm not mistaken). https://kit.svelte.dev/docs/service-workers#inside-the-service-worker . Instead of caching the assets, could it be possible to trigger a full page reload when an asset fails to be fetched? |
A service worker can't itself trigger a reload, it can only send a signal to the main thread to perform the reload. But it would certainly be a cleaner solution to detect 404s than But either way this can't be dependent on a service worker since it might not be installed yet for the request that this happens to. |
Describe the problem
From what I know it's not possible to hook into the serving of build artifacts in the
_app
folder. The biggest use case I have for it is to be able to hook into it to prevent 404s on assets that no longer exists which is an issue during deployment where clients are still on the "old" version in their browser.Another use case is being able to have middlewares for the build artifact files to set custom headers, but that's a lot less important.
Describe the proposed solution
Some way of registering a 404 handler for the _app folder or some sort of middleware where I would be able to detect a 404 and prevent it from really becoming a 404.
Alternatives considered
I'm not aware of a way to solve this except perhaps building my own Sveltekit adapter which feels overkill for this.
Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: