-
Notifications
You must be signed in to change notification settings - Fork 13
Description
Describe the bug
Client-side components are not rehydrated in the case where I navigate from Page A to Page B, then back to Page A. This means that any client-side components that previously worked on Page A when I first loaded it will cease to work when I return to it.
My understanding is that this is because the hydration scripts outputted by Astro are ES modules, and ES modules can only be evaluated once per page load. This means that the hydration scripts for Page A ran once to hydrate any client-side components (so it works initially), but on return to the page, since the page is not actually reloaded, the script will not run again (and therefore any client-side components will not be rehydrated) despite any attempts at re-injecting it to the head. Refer to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules#other_differences_between_modules_and_standard_scripts
EDIT: Just to elaborate a little, the core issue at hand here is not about the exact navigation sequence of Page A -> Page B -> Page A, but the fact that once a page has been visited, returning to it will lead to any client-side components no longer working. You can play around with the back/forward button and see that once any of the pages have been visited, any return to it will yield the same problem.
To Reproduce
Steps to reproduce the behavior:
- Go to https://test-astro-spa.vercel.app/
- Verify that Counter works in Index page.
- Click on "Next" link to go to /Next page.
- Click on "Back" link to return to Index page.
- Verify that Counter no longer works as it should.
Configuration for astro-spa
<Spa containerSelector="#container" />
Versions
- Astro: v0.22.18
- astro-spa: v1.3.8