lukeed / freshie

(WIP) A fresh take on building universal applications with support for pluggable frontends and backends.
MIT License
155 stars 2 forks source link

Allow HTML templating via UI library #10

Open lukeed opened 4 years ago

lukeed commented 4 years ago

Right now, only src/index.html is used as the HTML template. This is used in both client and server outputs.

An early wishlist-item was to allow the option for index.html.svelte when using Svelte or index.html.tsx when using Preact/React, for example. These would include the full <html .../> markup, with freshie only auto-prepending the doctype line 😆

Something like this might unlock a better/opinionated freshie system for dealing with meta tags and <title/>, for instance, because not all UI libraries have those abilities built-in like Svelte does. One possibility could be that any context.$ssr object properties would be accessible to this HTML component as render props.

Another thing – index.html.{extn} is just a special/top-level _layout.{extn} file. This means that it can have its own preload function too (user authentication, session data, etc).

The trick thing here is that layout files can only have 1 <slot/> / props.children placement. This makes injecting documeny.head vs document.body content difficult, especially since in the JSX-world, you can't dangerouslySetInnerHTML on a fragment, and you don't necessarily want to setHTML on the head or body outright either. Easy to workaround for body content, but not easy for head.