Closed rigor789 closed 4 years ago
I think f529dbd happens to address the issues you have here:
default()
slot and use as children)resolveDynamicComponent
falls back to native strings if component is not foundWe can simply replace resolveComponent
with resolveDynamicComponent
when hasUnknownElements
is true
. Does that solve your problem?
That sure sounds like the way to go!
So with hasUnknownElements
set to true
the following templates would produce the same render function:
<StackLayout>
<Label/>
</StackLayout>
<!-- would be the same as -->
<component is="StackLayout">
<component is="Label" />
</component>
Is that correct?
Yes, that's correct
Actually, since element vnodes can now accept slots as children, your approach of exporting a custom resolveComponent
from your runtime should already work, maybe we don't need the option at all.
I'll give it a try and report back!
That seems to be working with alpha.10
, thanks!
What problem does this feature solve?
In NativeScript we have a default set of elements, but plugins are allowed to register new elements - this results in most elements not being known at compile time, thus all unknown elements are treated as components in the render functions.
There's
isNativeTag
that's meant to solve this, however in our use-case it's not straight-forward. My initial approach was to treat everything as native elements, however this wouldn't work as all user-created components would stop working.Is there a possibility to optionally transfer this responsibility to the runtime?
What does the proposed API look like?
That would replace
resolveComponent
calls with a different resolver (perhapsresolveUnknownElement
) that we could export from our runtime.I tried to export a custom
resolveComponent
function from our runtime, but the problem is the children are then treated as slots. This would still need solving with theresolveUnknownElement
replacement, but I can't think of a solution yet.Example of the issue
Render function when we have unknown elements treated as components
Versus when the element is treated as a native element (replaced with
div
)📢 I'm very open for discussion, as I may be solving the wrong problem here.