Open tordeu opened 4 days ago
I don't think this is the same as nanostores/persistent#49
client:load
renders on the server, which has no persistency and is then hydrated on the client which adds the listeners and bindings.
I modified your reproduction with an alert that shows which value is being read on the client for each one of them: https://stackblitz.com/edit/github-6qhjd8-4sejou?file=src%2Fcomponent%2FstoreInput.tsx
Both components read the correct value on the client, but the client:load
won't replace the elements rendered on the server until the state changes.
It is unclear to me whether this is intentional with the rationale that the first render on the client should have the same result as the server render and, therefore, can skip changing the DOM.
This sounds very familiar to https://github.com/withastro/astro/issues/5937
Yeah, Preact expects the first render to match and doesn't update if it doesn't.
Interesting, thanks @Fryuni and @matthewp.
While client:load
renders the component on the server, I was expecting this to happen:
But because of your comment, I switched from preact to react and it is working as expected.
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I created a preact component using a persistent data store. I added two instances of the component in an astro page. Data is synchronized between them as expected. But when going to a different page and then coming back, the initial value is displayed.
In the console, I can see that
read()
is retrieving the correct value, though. It just looks as if no UI update is triggered afterwards. The component works as expected when using theclient:only
directive, but not when usingclient:load
orclient:visible
.Component:
(
console.log
statements andread()
function are merely added to log the values to the console.)Store:
Page:
What's the expected result?
I expected the component to display the correct value from localStorage when coming back to the page.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-6qhjd8?file=src%2Fcomponent%2FstoreInput.tsx
Participation