-
-
Notifications
You must be signed in to change notification settings - Fork 356
[LiveComponent] New placeholder macro to generate defer/lazy skeleton #1532
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
Conversation
I tried things with blocks (but you'd have to manually "not render it" when not in lazy), with includes (but i wanted to keep code in the same template), so it feel a good balance. |
This is nice! Does rendering loading content traditionally take priority over the macro? |
Yes, if you pass a loadingTemplate attribute it takes precedence. And the loadingTag is "around" for both cases. |
So the primary benefits are:
|
Exactly and the last one:
It's 100% optional and has no cost obviously :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems very sensible. Doing this with blocks, in theory, would be cool - but I totally agree that, in practice, it doesn't seem possible in a nice way.
@@ -43,7 +43,7 @@ public function __construct( | |||
private UrlGeneratorInterface $router, | |||
) { | |||
$this->client->catchExceptions(false); | |||
$this->data['attributes']['data-live-id'] ??= 'in-a-real-scenario-it-would-already-have-one---provide-one-yourself-if-needed'; | |||
$this->data['attributes']['id'] ??= 'in-a-real-scenario-it-would-already-have-one---provide-one-yourself-if-needed'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I missed this one :)
b4f00da
to
2130326
Compare
Thanks Simon! |
When you use defer/lazy component, you can customize the "loading" content in the calling template. But for components that you reuse on multiple pages, it can lead to code duplication.
Moreover, you cannot adapt the size / content depending on the props.
So... introducing the "
placeholder
" macro.If you define such macro in your lazy component template, it will be called to generate this temporary content.
Bonus, you'll get the props of your component as parameters.
So let's say you have a live component which load N comments behind an article.
When you set this prop to your live component, it will be passed to the placeholder macro, allowing you to fill the good amount of space / loading blocs in the HTML
What do you think ?