[LiveComponent] In a batch request, the backend only returned that view for the last call #2914
Replies: 7 comments
-
It may be a bug, or a documentation problem, so i don't think you are to blame here... and there are no stupid questions :) Let's try to narrow things down :) Do your dummy elements belong to the same LiveComponent or are they different ones ? Trying to understand what you expect regarding scrolling to "specific part of the page" |
Beta Was this translation helpful? Give feedback.
-
Hi smnandre, Thank you for your support! What I am trying to do is basically replicate the behavior of Photo-Gallery apps on mobile phones. In those, you can usually scroll to any point in time and the respective images are loaded. I grouped all my images by day, setting up the page with an empty div for each day and when I scroll to a specific point, the images for the placeholder divs in the viewport should be loaded. So, in your example, only the images for those days corresponding to the dummy div elements which are in the bottom 200px of the page should be loaded. This is all done in one LiveComponent. It works fine when there is only one of the dummy divs in the viewport. However, when the JS controller sends a batch request, all of the sub requests are handled by the PHP controller separately, but only the view rendering for the last handled sub request is send back to the JS controller. In that case, the last day is loaded correctly for the user, but the other days are not loaded but remain as dummies. Here is the skeleton of my PHP controller:
Here the twig html corresponding to it:
And the JS controller:
|
Beta Was this translation helpful? Give feedback.
-
That's expected.. there must be "one" reponse in the end, matching the state of the component (so here, the last day set by the actions). In the Infinite Scroll demo there is a strong notion of pages, and here you have some "sub-page" level or lazyness. Depending on what you want to do next in your UI, i can suggest you multiple solutions:
Depending on your app i'd suggest the "I'd recommand a LiveComponent per day" i think |
Beta Was this translation helpful? Give feedback.
-
Thank you again for taking so much time to help me! I have been playing around with the “Make every "day" a LiveComponent with loading=lazy” solution and have to say, that this is very cool. I somehow missed this functionality when I was reading through the documentation. This is pretty much what I wanted, and it is done automatically for me. However, with this solution I am losing quite a bit of control as there are no events anymore to hook into (as far as I have seen). There are three points in particular:
I did not find any way to implement those features when using the lazy loading solution. |
Beta Was this translation helpful? Give feedback.
-
Did it work when the user reloaded the page (and so scrolled automatically mid-page for instance) ?
Do you feel a big difference ? I would personnaly not load anything before it appears in the viewport, but if you need to you may cheat and use some CSS tricks to expand the placeholder size maybe ?
Does this not contradict the point 2 ? If you load before a div appears in the viewport but still add a 200ms delay, would these two things cancel ? |
Beta Was this translation helpful? Give feedback.
-
The planned behavior was as follows: I any case, I feel this is a bit too much to ask from the Live Component. This is a very cool tool that is just designed for a different use case. On the bright side, while fiddling with this and through your support, I learned so much that I will be easily able to implement a few lines of JavaScript myself to handle my requirements and just load the content in via a standard Symfony Controller. So, again, thank you very much for your support! Highly appreciated! |
Beta Was this translation helpful? Give feedback.
-
It's been a pleasure! And feel free to suggest / ask features in the future. We cannot implement all but that is always interesting to get feedback, ideas, etc! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I apologize in advance if this is not a bug and I am just very stupid.
Using UX Live Component, whenever there are multiple actions called in the JS Controller roughly at the same time, a batch request to the backend is done that translates into multiple Sub Requests in the HttpKernel. All Sub Requests are executed fine, however, only the view rendering for the last Sub Request is returned to the browser.
To give you more context: I am basically following the Infinite Scroll - 2/2 Tutorial (https://ux.symfony.com/demos/live-component/infinite-scroll-2), however, as I have a complex layout and want to be able to scroll to specific parts of the page quickly, I am setting up dummy elements for all potentially-to-be-loaded content right at the beginning and have Intersection Observers on all of the dummy elements to load in the real content once they come into the viewport. Every time I quickly scroll to a specific part of the page that has multiple dummy elements in view, the batch call is initiated, but is only loading in the content for the last element.
One additional piece of information: I am working with Pimcore. Not sure, if they changed Symfony’s standard behavior in the HttpKernel.
Thank you!
Fabian
Beta Was this translation helpful? Give feedback.
All reactions