solid-start icon indicating copy to clipboard operation
solid-start copied to clipboard

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

Open raflymln opened this issue 1 year ago • 3 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the 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!

raflymln avatar Aug 19 '24 09:08 raflymln

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..

ryansolid avatar Aug 19 '24 18:08 ryansolid

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

Brendonovich avatar Aug 19 '24 20:08 Brendonovich

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.

raflymln avatar Aug 19 '24 21:08 raflymln