-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Description
A proposal for first-class async component support:
<:Async src:'./Widget.html' loading:LoadingComponent error:ErrorComponent foo='{{bar}}'>
contents go here
</:Async>
<script>
import LoadingComponent from './LoadingComponent.html';
import ErrorComponent from './ErrorComponent.html';
export default {
components: {
LoadingComponent,
ErrorComponent
}
};
</script>
Behind the scenes that would become roughly equivalent to this...
{{#if ready}}
<Widget foo='{{bar}}'>
contents go here
</Widget>
{{elseif error}}
<ErrorComponent/>
{{else}}
<LoadingComponent/>
{{/if}}
...except that you wouldn't need to declare Widget
ahead of time.
It would get transpiled to import('./Widget.html').then(...)
in dom
mode, but could be an inline require('./Widget.html')
in ssr
mode.
Advantages of this approach over a 'just use a component' approach, for the benefit of @TehShrike 😉 :
- One clear blessed way to do it, with documentation etc, that's used consistently across the ecosystem. No need to mess around with external libraries. It's the difference between
<ReactCSSTransitionGroup>
andin:fade
. - Optimisations. We haven't talked much yet about app-level analysis/compilation, but there are certain potential compile-time wins that you get from knowing the structure of an application ahead of time. The more you know...
- With dynamic components you have a tricky SSR problem — a hypothetical
<Async>
component (as opposed to<:Async>
) would have to do its work inoncreate
, which doesn't run on the server. With<:Async>
we can load the component synchronously withrequire(...)
and generate markup without 'loading...' messages. - It's not mutually exclusive with 'just use a component' approaches if you have some truly exotic requirements.
stalkerg, psirenny, nikku, amadeu2, paulocoghi and 2 more
Metadata
Metadata
Assignees
Labels
No labels