Skip to content
back to blog
developmentNovember 29, 2026 · 4 min read

SvelteKit 3: The Breaking Changes Your Migration Script Won't Catch

sv migrate handles the renames in SvelteKit 3. These six behavior changes still compile cleanly and break at runtime, so audit them by hand.

Dan Holloran
Dan Holloran
Senior Fullstack Developer
SvelteKit 3: The Breaking Changes Your Migration Script Won't Catch

SvelteKit 3 shipped on October 1st, and the upgrade path is about as smooth as a major version gets. One command does most of the work:

bash
npx sv migrate sveltekit-3 --tasks all --confirm

It moves your config from svelte.config.js into the sveltekit() plugin in vite.config.ts, rewrites $lib imports to #lib subpath imports, swaps $app/stores for $app/state, and leaves a TODO list for whatever it couldn't handle. Run it, fix the TODOs, get a green svelte-check, ship.

The catch is that the riskiest changes in the migration guide aren't renames. They're behavior changes. Your code still compiles, your types still pass, and your app now does something different at runtime. A codemod can't flag those because there's nothing syntactically wrong. Here are the ones worth auditing by hand.

Your error hook just got a lot louder ​

In SvelteKit 2, handleError only ran for unexpected errors. If you threw error(404, 'Not found') from a load function, the hook never saw it. In SvelteKit 3, every error goes through handleError, including the expected ones, plus rendering errors and validation errors (which arrive with kind: 'validation' now that handleValidationError is gone).

If your hook forwards everything to Sentry, every 404 from a bot crawling /wp-admin is about to become an incident. Filter expected errors explicitly:

ts
// src/hooks.server.ts
import { isHttpError } from "@sveltejs/kit";
import type { HandleServerError } from "@sveltejs/kit";

export const handleError: HandleServerError = ({
  error,
  event,
  status,
  message,
}) => {
  if (isHttpError(error) && status < 500) {
    // expected: 404s, 403s, etc. Don't page anyone.
    return { message, status };
  }

  reportToTracker(error, { route: event.route.id });
  return { message: "Something went wrong", status };
};

Two related changes ride along. App.Error now always includes status, and error(...) takes its extra properties as a third argument. The second argument must be a string. Code like error(400, { message: 'Bad input', code: 'E_INPUT' }) needs to become error(400, 'Bad input', { code: 'E_INPUT' }). TypeScript catches this one, but only if the call site is typed.

Also check your tests: enhanced form action responses now return the status you passed to fail(...) instead of a blanket 200. Any assertion like expect(res.status).toBe(200) on a failed submission will start failing.

Three changes to $app/navigation look harmless in a diff and bite in production:

  • goto rejects for URLs that don't match a route. External URLs already rejected in SvelteKit 2; now a same-origin path with no matching route, like goto('/api/export'), rejects too. If you don't await and catch, that's an unhandled rejection. Use window.location.href for anything outside your route tree.
  • preloadData can return an error. It used to report { type: 'loaded' } with a 200 even when the target page failed. Now you get { type: 'error', status, error }. Any code that branches on result.type needs an error case, or it falls through silently.
  • Clicking a link to the current page refreshes it. SvelteKit now calls refreshAll() instead of doing nothing. If you have a nav link to /dashboard on /dashboard and that page runs an expensive load, users who habitually click the logo just re-ran it.

The option renames on goto (replaceState → replace, keepFocus/noScroll → reset: false, invalidateAll → refreshAll) are mechanical, but read refreshAll carefully: unlike invalidateAll, it does not reset page.state. That's usually what you wanted with shallow routing, but if you relied on the reset to close a modal, the modal stays open.

Redirects and update checks changed defaults ​

redirect() to an external URL now requires an explicit opt-in:

ts
import { redirect } from "@sveltejs/kit";

// SvelteKit 2: just worked
// SvelteKit 3: needs `external`
redirect(303, "https://billing.example.com/portal", {
  external: ["https://billing.example.com"],
});

Passing an allowlist of origins is better than external: true. If the target comes from user input (a ?next= param), the allowlist is the difference between a redirect and an open-redirect vulnerability. This is a good change; it just means OAuth callbacks and payment handoffs throw until you update them.

The other quiet default: version.pollInterval now defaults to one hour, and updated.current flips to true on navigations, remote function calls, and when the tab regains focus. If you built a "new version available, reload?" banner on updated.current, it was mostly dormant before. Now it will actually show up, which may surprise users and your QA team. If you're on Vercel with skew protection, the docs note the navigation-based checks can report false negatives, though polling and focus checks still work.

A migration checklist that goes past the codemod ​

After sv migrate finishes and svelte-check passes, grep for these before you deploy:

  • handleError: add filtering for expected errors
  • error( calls with an object second argument
  • goto( calls that aren't awaited or point outside your routes
  • preloadData( result handling
  • redirect( to any absolute URL
  • updated.current and anything listening to it
  • Tests asserting 200 on failed form actions

None of this takes long, but none of it shows up as a red squiggle either. Treat the migration script as the start of the upgrade, not the end, and read the full migration guide once with these behavior changes in mind.

~/subscribe
# new posts on code, craft & travel — no noise, no schedule