-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: resolve WebComponent constructor within h() #704
Comments
@Hotell I am trying to figure out how Preact could actually resolve this itself - how would it know the given function isn't a Component or pure functional Component? I can't remember if I've suggested it before, but would it be feasible to do something like this in skate? There'd be two options there - the first is to provide that functionality via your re-exported import { createElement } from 'preact';
// (in 8.x createElement is an alias of h, using it here to avoid name conflict)
export function h(nodeName, ...args) {
if (typeof nodeName==='function' && typeof nodeName.is==='string') {
nodeName = nodeName.is;
}
return createElement(nodeName, ...args);
} Option 2 would be to use preact's hooks to inject the Web Component constructor swapping into anything using Preact, even non-skate things: import { options } from 'preact';
let oldHook = options.vnode;
options.vnode = vnode => {
// this is super cheap because it mutates VNodes in-place and doesn't change shape
if (typeof vnode.nodeName==='function' && typeof vnode.nodeName.is==='string') {
vnode.nodeName = vnode.nodeName.is;
}
if (oldHook) oldHook(vnode);
} |
both solutions look good although that one where you check for
checking prototype of the element I guess ? if (Object.getPrototypeOf(nodeName) === HTMLElement) {
return new nodeName();
} cc @treshugart |
I messed with this a bit today and got it working at the diff level while only changing a few lines of code. Problem is, we need the new Babel because the version Preact is currently on doesn't transpile classes correctly to extend natives. Babel is being upgraded in #683 and I have all the code ready to go for this change. |
💥 #715 💥 |
Sweeeeeeet Christmassss ! |
@developit see PR, but re:
Basically |
Custom Elements also inherit from Node so Is |
This would also be a good approach. Happy to explore that option.
It's the furthest up it can extend. Custom elements can extend other custom elements, though. |
Closing as it's not something we're going to do. Since the time this issue was created there have been new jsx functions in |
As you know https://github.com/skatejs/skatejs 5.x is using Preact as default renderer ( we switched from Incremental DOM )
What would be awesome, is to add support for resolving custom-elements constructors within
h
so we can provide functionality like in v4:so
<MyUserCard user={this.data} />
will be recognised byh
that it's a custom element and will output -><my-user-card></my-user-card>
This feature would also add better support to raw WebComponents which as win win for everyone #useThePlatform
The text was updated successfully, but these errors were encountered: