shepherdjerred / astro-opengraph-images

Generate Open Graph images for your Astro site.
https://www.npmjs.com/package/astro-opengraph-images
GNU General Public License v3.0
9 stars 2 forks source link

preact? #38

Closed jcayzac closed 1 week ago

jcayzac commented 2 weeks ago

I use the same flow in my wip website based on astro-paper, but I migrated from using react to just using preact as it's smaller and loads faster (and I don't use react anywhere else, so it seemed wasteful to pull all these extra dependencies just for satori).

Could be some optimization here. You don't have any interactivity or effect in static images so you probably don't need anything as fancy as react :)

shepherdjerred commented 2 weeks ago

I agree. The only reason I'm pulling in React as a dependency is for the types. Satori does expect input of the type ReactNode, but maybe there's something else we can do here.

https://github.com/vercel/satori/blob/fe2534a3b8b9cf2a01c04041d982f196d10e2810/src/satori.ts#L45-L46

The good thing is that React wouldn't effect your bundle size at all since it wouldn't be served to clients. This would really only effect your development environment.

jcayzac commented 2 weeks ago

satori accepts prect's VNodes, but yes you have to pass them using node as unknown to avoid TS warnings.

shepherdjerred commented 1 week ago

While we could switch to Preact, I'd prefer to stay with React since it's more familiar and widely used.

Using Preact would be beneficial to decrease the number of dependencies this project has, but considering that React is so well-known I don't think there is a significant risk by relying on it. I don't think there's much of a drawback to requiring React in this case since it has no effect on what's shipped to the client.

Long-term I'd like to move React as an optional dependency that would only be required if you want to use a preset renderer. Custom renderers can use whatever JSX transform they'd like.