Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better support for templates and/or child elements #12

Open
loreanvictor opened this issue Jun 30, 2023 · 0 comments
Open

Better support for templates and/or child elements #12

loreanvictor opened this issue Jun 30, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@loreanvictor
Copy link
Owner

loreanvictor commented Jun 30, 2023

Right now, writing a component that handles templates and child elements works as follows:

define('say-hi', () => {
  const tmpl = document.createElement('template')
  tmpl.innerHTML = '<div>Hellow <slot></slot></div>'

  return tmpl.content.cloneNode(true)
})

This is pretty clunky, and it also doesn't support SSR (since the return value is a Node not an SSRTemplate). Perhaps better support for handling templates and child elements can be baked in?

A naive implementation would be to use DOMParser when a string is returned, and if the described node is an HTMLTemplateElement, then use .content.cloneNode(true) to handle slots properly. A similar approach could be used for when a Node is returned, and when an SSRTemplate's .create() method returns a Node.

Note that this might be the scope of helper libraries that allow creating templates. For example, right now rehtm does support templating and child elements quite nicely, but I feel it would be nice to add some more direct support as well (though the performance impact of this should also be analyzed).

@loreanvictor loreanvictor added the enhancement New feature or request label Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant