solidjs / solid-start

SolidStart, the Solid app framework
https://start.solidjs.com
MIT License
5.21k stars 373 forks source link

[Feature?]: Set Page Metadata by Exporting `metadata` Variable #1605

Open raflymln opened 3 months ago

raflymln commented 3 months ago

Duplicates

Latest version

Summary πŸ’‘

I think it'd be great if solid implement the metadata handling that nextjs use, instead of we using solid-meta, it'd be much easier if we can just export metadata variable from a file and let that assigned as a metadata for that page.

Seeing that SolidJS is compiling it's DOM using compiler, i think this is possible to create on client too, while on nextjs it's only available on server.

While i think that the dynamic metadata will only be supported on server, i think having static metadata on client will be a great improvement to solidjs developer experience.

Examples 🌈

https://nextjs.org/docs/app/building-your-application/optimizing/metadata

export const metadata: Metadata = {
  title: '...',
  description: '...',
}

Motivation πŸ”¦

  1. It'd be much easier to organize the code, since i myself always put the metadata variable export on the top of the file (after imports)
  2. If parent inheritance is supported, it'd be much easier to maintain a templated page title, for example {page name} | Site Name.
  3. Cleaner and improved DX
  4. Less imports, i don't need to import bunch of components for metadata like Title, Link, Meta

I believe that this isn't going to be priority for solidjs team, but i hope this will be considered by the team as a way to improve dx. Thanks!

ryansolid commented 3 months ago

Thing I wonder about this always is how does async data fit into this. Like if the title is based on say a user you need to load. I'm unclear what the desired timing is etc..

Brendonovich commented 3 months ago

The Next solution to async data is to allow exporting either a metadata constant or a generateMetadata function that can be async that blocks HTML streaming

raflymln commented 3 months ago

Well async is there if you implement the generateMetadata function, and because of that, I hope at least the static metadata will be implemented for now

As for generateMetadata, it's basically only supported on server, basically it'd be executed first before streaming the HTML to the client, so if you got a long duration function in the generateMetadata function, the page will be loaded longer, kind like PHP.