You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the case that a form action throws a redirect(), it seems that using the browser back navigation will not correctly set the AfterNavigation object passed to the callback of afterNavigate.
Normally, browser back navigation shows popstate as the type, like this:
I believe this issue occurs because your form submission does a full page reload, causing the client side router to re-initialise on the redirected page, and also when you press back.
You’ll need to enhance your form to retain the client-side routing history.
Oh yeah - I did notice that it worked if enhance were set. I was a bit worried about the behavior being different for non-javascript enabled users, although I guess that is somewhat of an academic concern.
I am curious whether in this situation, back navigation could be inferred that the navigation was a browser navigation using the back/forward cache. I'm pretty sure bfcache would be correct in the case.
However, I don't think pageshow actually works at all in svelte kit (although it seems to have been added in the past). For example, the following never alerts on any page:
... although of course I have no idea how complex adding an event listener for pageshow on the window object would be, and that would be a separate issue probably.
What do you think? I'm fine just using enhance myself, but I figured I'd ask.
The pageshow event probably isn't fired because it's listened to too late.
Infering this from back/forward cache is unreliable and could be confusing/breaking expectations of behavior elsewhere.
Closing since the issue is solved through use:enhance
Describe the bug
In the case that a form action throws a
redirect()
, it seems that using the browser back navigation will not correctly set theAfterNavigation
object passed to the callback ofafterNavigate
.Normally, browser back navigation shows
popstate
as the type, like this:However, if I submit to a form action, get redirected, and then use the browser back button, it just looks like an initial load:
I would expect
from
to be set here andtype
to be"popstate"
, like in the first example.Reproduction
See https://github.com/fzembow/sveltekit-after-navigation-bug
STEPS
yarn dev
/other-page
RESULT
Observe that the navigation type is
"enter"
and not"popstate"
, and thatfrom
is null.EXPECTED
I would expect the navigation type to be
"popstate"
and for"from"
to be set.This is the first page
/routes/+page.svelte
This is that page's actions:
/routes/+page.server.ts
And this is the target page (doesn't really matter what the content is here since we will just use the browser back)
/routes/other-page/+page.svelte
Logs
No response
System Info
The text was updated successfully, but these errors were encountered: