You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SvelteKit currently does not support a true equivalent of Next.js middleware.ts — a middleware layer that runs before a static asset is served (e.g. prerendered .html). This severely limits the ability to implement common use cases like internationalization redirects, A/B testing, geolocation-based content, and cookie inspection without giving up SSG.
Problem:
In Next.js, middleware.ts runs before a static page is served from the CDN. This allows developers to:
Read headers and cookies
Dynamically redirect (/ → /en)
And still serve prerendered content
In SvelteKit:
hooks.server.ts only runs on SSR or Edge runtime
But does not run at all for prerendered routes
So, to implement dynamic logic (e.g. locale detection), we must disable prerendering, which:
Slows down response times
Breaks CDN-level caching
Describe the proposed solution
Possible solutions:
Add a middleware.ts-like system that runs before routes are resolved, even for static pages
Allow limited hooks to run during static asset delivery when deployed via Vercel/Cloudflare
Add official integration with Vercel's Edge Middleware layer that plays nicely with SvelteKit’s router
Alternatives considered
As a result, we either:
Accept client-side FOUC (e.g. for i18n redirects)
Or lose SSG/CDN benefits by turning off prerendering
Next.js has solved this very well. SvelteKit currently has no equivalent.
Importance
i cannot use SvelteKit without it
Additional Information
Can the SvelteKit team provide an official position on this limitation, and whether "true edge middleware before static delivery" is on the roadmap?
The text was updated successfully, but these errors were encountered:
What is your use case?
You can place a middleware.js file at the root and it will be picked up by vercel, it doesn't get recognized at dev time though.
Related: #13477 / #13430
"Due to SvelteKit's client-side rendering, you cannot use Vercel's Edge Middleware with SvelteKit."
So it seems to me that the middleware.js file won't work, however I haven't actually tried it. I'll let you know if this resolves the issue for my use case.
Since the PR state is draft, that means that for now edge middlewares on vercel don't work until PR is merged? If so, that's all I wanted to know and I can close the issue.
Describe the problem
Summary:
SvelteKit currently does not support a true equivalent of Next.js middleware.ts — a middleware layer that runs before a static asset is served (e.g. prerendered .html). This severely limits the ability to implement common use cases like internationalization redirects, A/B testing, geolocation-based content, and cookie inspection without giving up SSG.
Problem:
In Next.js, middleware.ts runs before a static page is served from the CDN. This allows developers to:
Read headers and cookies
Dynamically redirect (/ → /en)
And still serve prerendered content
In SvelteKit:
hooks.server.ts only runs on SSR or Edge runtime
But does not run at all for prerendered routes
So, to implement dynamic logic (e.g. locale detection), we must disable prerendering, which:
Slows down response times
Breaks CDN-level caching
Describe the proposed solution
Possible solutions:
Add a middleware.ts-like system that runs before routes are resolved, even for static pages
Allow limited hooks to run during static asset delivery when deployed via Vercel/Cloudflare
Add official integration with Vercel's Edge Middleware layer that plays nicely with SvelteKit’s router
Alternatives considered
As a result, we either:
Accept client-side FOUC (e.g. for i18n redirects)
Or lose SSG/CDN benefits by turning off prerendering
Next.js has solved this very well. SvelteKit currently has no equivalent.
Importance
i cannot use SvelteKit without it
Additional Information
Can the SvelteKit team provide an official position on this limitation, and whether "true edge middleware before static delivery" is on the roadmap?
The text was updated successfully, but these errors were encountered: