withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
45.48k stars 2.38k forks source link

Static/server rendering fails with Preact class components #10388

Open lilnasy opened 6 months ago

lilnasy commented 6 months ago

Astro Info

Astro                    v4.5.0
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/preact

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Component renders twice and this.state is always {} the second time, resulting in a runtime error.

export default class extends Component {
  state = { poo: { bar: 'hello' } };
  render() {
    return <div>{this.state.poo.bar}</div>;
  }
}

What's the expected result?

The component renders on the server successfully same as it does in the browser with client:only directive.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-2lvdty?file=src%2Fpages%2Findex.astro,src%2Fcomponents%2FCounter.tsx

Participation

matthewp commented 6 months ago

I thought we had an instanceof check in the Preact renderer. Might verify that's correct.

lilnasy commented 6 months ago

We don't. That would be upto preact-render-to-string, I'm guessing.