S
SolidJS2mo ago
gsoutz

How do I do something after a redirect, like reload the page, or in this case reconnect a websocket?

there is no redirect reload, or some kind of hook that gets called after a redirect has happened to the same dynamic route with different params.
8 Replies
ChrisThornham
ChrisThornham2mo ago
Couldn't you use onMount() or createEffect() on the page you are redirecting to? Basically, when this page loads, check for a websocket connection. If it exists, return. If not, reconnect.
gsoutz
gsoutzOP2mo ago
I have this dynamic route u/:username The action changes the username invalidates the user and redirects to u/hello to u/world , and I can't get any notification on anywhere. Except onBeforeLeave occurs but I get the old username 'hello'. I need a callback after the cache invalidates, so I can reconnect the websocket.
let action_reset_profile = useAction(action(async() => {
"use server"
let user = await resetUser()

return redirect(`/u/${user.username}`, { revalidate: ['get_user']})
}))
let action_reset_profile = useAction(action(async() => {
"use server"
let user = await resetUser()

return redirect(`/u/${user.username}`, { revalidate: ['get_user']})
}))
ChrisThornham
ChrisThornham2mo ago
I think you'll have to recall your getUser function on each load. Or store the current user name. Then check it on page load. If the user name is the same, proceed. But if the user name has changed, rerun getUser.
REEEEE
REEEEE2mo ago
GitHub
GitHub - solidjs/solid-router: A universal router for Solid inspire...
A universal router for Solid inspired by Ember and React Router - solidjs/solid-router
REEEEE
REEEEE2mo ago
in an effect to see when the param has changed and do the changes
gsoutz
gsoutzOP2mo ago
useParams doesn't react to changes, I've also used a custom signal and tried to change that and it gave error, set_a is not defined.
export default function Home() {
const params = useParams()

let [a, set_a] = createSignal(1)
let { send, page, cleanup } = useContext(SocketContext)!
onMount(() => {
page('site')
})

let profile = createAsync(() => getProfile(params.username))
let user = createAsync(() => getUser())
createEffect(() => {
console.log(a())
})

let action_reset_profile = useAction(action(async() => {
"use server"
let user = await resetUser()

let res = redirect(`/u/${user.username}`, { revalidate: ['get_user']})

set_a(3)
return res
}))
export default function Home() {
const params = useParams()

let [a, set_a] = createSignal(1)
let { send, page, cleanup } = useContext(SocketContext)!
onMount(() => {
page('site')
})

let profile = createAsync(() => getProfile(params.username))
let user = createAsync(() => getUser())
createEffect(() => {
console.log(a())
})

let action_reset_profile = useAction(action(async() => {
"use server"
let user = await resetUser()

let res = redirect(`/u/${user.username}`, { revalidate: ['get_user']})

set_a(3)
return res
}))
REEEEE
REEEEE2mo ago
createEffect(() => {
console.log(params.username)
})
createEffect(() => {
console.log(params.username)
})
Does this effect log the changes to the username if you add it?
gsoutz
gsoutzOP2mo ago
omg that worked thanks.
Want results from more Discord servers?
Add your server