#Astro SSR: Framework components render only once

25 messages · Page 1 of 1 (latest)

grand thicket
#

Hi. This might be a basic question, but I can't figure out what I'm missing.
I have enabled SSR. However, the following React component does not re-render when I refresh the page.
The equivalent astro component works through.

const nameQueryResult = Date.now();

export default function MyNameComponent() {
    return <div>Hello {nameQueryResult}!</div>;
}

Seems like Astro is serving a static version of the component.
How can I make this component re-render on every request?
Thanks in advance!

#

Astro SSR: Framework components render only once

modest nexus
#

Hi. Are you reloading with the reload icon, CTRL+r or CTRL+shift+r?

grand thicket
#

@modest nexus Tried both. It just render the component once and servers the same thing again and again 🤔

modest nexus
#

With CTRL+shift+r too?

grand thicket
#

No luck 😭 When I refresh, all the Astro components update. Only the react one stays static.

modest nexus
#

Interesting. I’m not very familiar with react so I can’t really help you. Hopefully someone with more react knowledge sees this

grand thicket
quick atlas
rocky drift
#

If ‘export const prerender = true;’ or ‘const prerender = true’ set? I’m on mobile device so couldn’t check your code.

fierce arch
#

FYI i can't reproduce what you're showing!

#

when I refresh the page, the UI updates

grand thicket
fierce arch
#

ah, thank you!

#

i completely missed this

#

my guess is that because it is global in the file, that value doesn't get updated on every render. In React, there is nothing saying that that FILE re-runs when you refresh the code, only the component.

#

this is different from Astro, where the frontmatter always re-runs on every page

grand thicket
#

Thank you guys! Please let me know if there is a way to make react re-render.

south galleon
grand thicket
#

@south galleon That implies an async call, which does not work when moved into the component.
Can someone confirm if this is a bug or the design?

south galleon
#

Definitely not a bug, that's just how JavaScript modules work

#

The body of an imported module only runs once

south galleon