#Page-level SSR doesn't run when navigating backwards in history

1 messages · Page 1 of 1 (latest)

glacial pike
#

Hey all!
I've been experimenting with Astro's SSR features by making a little app to manage my family's cabin and noticed that pages don't seem to re-render when you navigate backwards through your browser history. *This can be a relatively serious issues especially when you are server-side rendering auth-gated content. *

**For example: **

  • I login to my app on /login and am redirected to /
  • I then navigate to /calendar
  • I then navigate to /
  • I then logout by navigating to /logout (which removes my session cookie, and deletes the session from the db) and am redirected to /login
  • if I know click "back" on my browser, I'm able to navigate through all of the staticly rendered "pages" I saw when authenticated (note: if I manually refresh these pages they force me to the /login route as expected)

Is there a way to force a rerender in these cases? I'm guessing this is happening because the page is cached, is the fix as simple as adding no-cache headers to each page?

I do realize I can avoid this by shifting all of my logic to client-side islands Preact/React/Svelte/whatever but for most of what I'm doing HTML rendered at the server on request is more than enough! I would like to stick with that for everything except the highly dynamic parts 🙂

**Links and reproduction account: **
Repo: https://github.com/MykalMachon/cabin/tree/dev/packages/webapp
Example: https://cabin-dev.up.railway.app/
email: [email protected]
password: AstroTestTime123

GitHub

a webapp to keep track of what's going on at the gregory cabin - MykalMachon/cabin

jovial flame
#

this is difficult. it's not cached exactly, but it's kept "in memory"? I guess.
You could add a small inline script to detect and warn the user, like this:

window.onbeforeunload = function() { return "Your work will be lost."; };

or use the history API and some event listeners to override the default browser behaviour