Absolute redirects inside `cache` are ignored if not called in `load`
Brendonovich opened this issue · 0 comments
Brendonovich commented
Describe the bug
From solidjs/solid-start#1512 (comment)
import { type RouteDefinition } from '@solidjs/router'
import { cache, createAsync, redirect } from '@solidjs/router'
import { getRequestEvent } from 'solid-js/web'
const exampleAction = cache(async () => {
'use server'
const location = new URL(getRequestEvent()!.request.url)
return redirect(`${location.origin}/target`)
}, 'exampleAction')
export const route = {
load() {
// redirect will start working if uncommented:
// void exampleAction()
},
} satisfies RouteDefinition
export default function Component() {
const data = createAsync(() => exampleAction())
return <h1>Result: {data()}</h1>
}
With the route above, when you navigate to /redirect, it does not redirect you to /target.
Unless you trigger an action with redirect inside route.load or use a relative redirect which starts with / instead of a full URL with the origin, i.e., redirect('/target') works, but redirect('http://localhost:3000/target') does not.
Your Example Website or App
N/A
Steps to Reproduce the Bug or Issue
Use the above code in an SSR route
Expected behavior
Redirect happens without a load function.
Screenshots or Videos
No response
Platform
N/A
Additional context
Am fixing this rn