Lazy DOM Rendering for Hidden Components #2435
Unanswered
bobik1337
asked this question in
Feature Requests
Replies: 1 comment 2 replies
-
|
@bobik1337 thanks for the request! We recently introduced Islands in Livewire v4 for exactly this reason. You can wrap the contents of a select in an island and add lazy to it, so it will only load when the select has been opened. See here for details https://livewire.laravel.com/docs/4.x/islands |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
When rendering multiple
flux:selectcomponents with large option sets, performance degrades significantly:Example scenario: 20 products × 500 product groups = 10,000
<flux:select.option>elementsThis causes three issues:
Issue 3 is the most critical for UI responsiveness, as all options are rendered upfront even though they're hidden until the select is opened.
Proposed Solutions
Solution 1: Lazy Option Rendering
Add a prop (e.g.,
defer-options) toflux:selectthat defers option rendering until the dropdown is opened.Why a prop? This creates a small latency when the dropdown opens (options need to render), so it should be optional behavior. Developers can choose to use it only when dealing with large option sets where initial page load performance is more critical than dropdown open speed.
Also it may require some changes at flux.js.
Livewire already implements similar lazy rendering using
x-iftemplates. This approach could be adapted for Flux components.Benefits:
Solution 2: Shared Option Pool (Advanced)
For pages with multiple selects sharing the same options, render the option list once and reuse it across all select instances.
Benefits:
Working Implementation
Both solutions are already implemented together in
x-if-demo.blade.php(see discussion at #2334 (comment)). This demonstrates the feasibility and performance benefits of the approach.Broader Application
This lazy rendering pattern could benefit all initially-hidden components:
Context
Related discussion: #2334 (comment)
Inspired by @calebporzio Blaze Demo.
Beta Was this translation helpful? Give feedback.
All reactions