Skip to content

Lazy option on block builder#19867

Open
KianAcquoy wants to merge 9 commits into
filamentphp:4.xfrom
KianAcquoy:feature/lazy-block-builder
Open

Lazy option on block builder#19867
KianAcquoy wants to merge 9 commits into
filamentphp:4.xfrom
KianAcquoy:feature/lazy-block-builder

Conversation

@KianAcquoy

Copy link
Copy Markdown

Solves: #5401

Description

Builder components with many items are slow to render because every block's schema is evaluated and sent to the browser on initial page load, regardless of whether the user ever opens those items.

This PR adds opt-in lazy loading to the Builder component. Calling ->lazy() makes the builder collapsible and starts every item collapsed. Each item renders only its header and a loading placeholder on first load. When the user expands an item, a Livewire call triggers loadItem, which renders the block's schema and injects it into the page.

Builder::make('content')
    ->blocks([/* ... */])
    ->lazy()

State is always kept in the parent Livewire data array, values survive collapse/expand cycles and page reloads. Validation still runs against unloaded items: if a required field is missing in a collapsed block, the item is automatically expanded and loaded on submit.

Per-block opt-out: Block::make(...)->lazy(false) on an individual block forces it to render eagerly even inside a lazy builder.

Unload on collapse: ->lazy(unloadOnCollapse: true) removes a block's schema from the DOM when the user collapses it again.

Visual changes

Instead of instantly opening the collapsed block, it will open with a loading state.
image

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

@github-project-automation github-project-automation Bot moved this to Todo in Roadmap May 15, 2026
@danharrin danharrin added enhancement New feature or request pending review labels May 20, 2026
@danharrin danharrin added this to the v4 milestone May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pending review

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants