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.

Redirects in `load` functions break when running client-side

See original GitHub issue

Describe the bug

There appears to be no way to use the new redirect method and disable SSR globally.

Reproduction

  1. Create a new skeleton project
  2. Create src/routes/page.ts with the contents:
import { redirect } from "@sveltejs/kit";

export function load() {
  throw redirect(307, "/about")
}
  1. Create src/hooks.ts with the contents:
import type { Handle } from '@sveltejs/kit'

export const handle: Handle = async ({ event, resolve }) => {
  return resolve(event, { ssr: false })
}
  1. Navigating to root now results in an error page, with the redirect class passed to it, instead of being redirected to “/about”

Repo: https://github.com/WaltzingPenguin/sveltekit-redirect-hooks

Logs

No response

System Info

System:
    OS: Windows 10 10.0.19043
    CPU: (12) x64 AMD Ryzen 5 1600 Six-Core Processor
    Memory: 7.50 GB / 15.95 GB
  Binaries:
    Node: 16.15.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.10 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.20.3 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 104.0.5112.81
    Edge: Spartan (44.19041.1266.0), Chromium (104.0.1293.54)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.64
    @sveltejs/kit: next => 1.0.0-next.413
    svelte: ^3.44.0 => 3.49.0
    vite: ^3.0.0 => 3.0.8

Severity

blocking an upgrade

Additional Information

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:20
  • Comments:40 (23 by maintainers)

github_iconTop GitHub Comments

14reactions
Rich-Harriscommented, Aug 26, 2022

Progress update — there’s now an PR against Vite that fixes this issue: https://github.com/vitejs/vite/pull/9848

6reactions
maximeduprecommented, Aug 28, 2022
Read more comments on GitHub >

github_iconTop Results From Across the Web

I am running into multiple problems with load functions - Reddit
Sadly, supabase runs only on the client side and it needs to access localstorage for storing. It only works when it is used...
Read more >
Stop using client-side route redirects - Kent C. Dodds
First, the goal of using a client-side redirect (like with Redirect's from prop or similar) is to ensure the user doesn't land on...
Read more >
Redirections in HTTP - MDN Web Docs - Mozilla
In HTTP, redirection is triggered by a server sending a special redirect response to a request. Redirect responses have status codes that start ......
Read more >
Next.js Redirect from / to another page - Stack Overflow
It handles both server side and client side. The fetch call is the one that actually get the auth token, you might want...
Read more >
HTTP redirect codes for SEO explained - ContentKing
Redirects play an important role within SEO, so it's important to know what ... Back button: client-side redirects break the Back button.
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