Skip to content
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

Absolute redirects inside cache are ignored if not called in load #438

Closed
Brendonovich opened this issue Jun 7, 2024 · 0 comments · Fixed by #439
Closed

Absolute redirects inside cache are ignored if not called in load #438

Brendonovich opened this issue Jun 7, 2024 · 0 comments · Fixed by #439

Comments

@Brendonovich
Copy link
Contributor

Brendonovich commented Jun 7, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant