Skip to content

defer Closure evaluation for append() and prepend()#213

Merged
CodeWithDennis merged 1 commit into
CodeWithDennis:4.xfrom
gp-lnuff:4.x
May 22, 2026
Merged

defer Closure evaluation for append() and prepend()#213
CodeWithDennis merged 1 commit into
CodeWithDennis:4.xfrom
gp-lnuff:4.x

Conversation

@gp-lnuff

Copy link
Copy Markdown
Contributor

Currently, the prepend() and append() methods evaluate a Closure passed to them as soon as it is given.
This creates issues when we want to inject utilities such as $livewire in the Closure - it will throw an Exception along the lines of "$container must not be accessed before initialization".

With this PR, two new methods are added:

  • getAppendedItems(), which evaluates $this->append and performs the checks on the value that were moved from append()
  • getPrependedItems(), which evaluates $this->prepend and performs the checks on the value that were moved from prepend()

Then, in getTree(), we wrap $this->append and $this->prepend in a filled() call, so that the when() does not evaluate the Closure prematurely, and we use the two new methods to retrieve the appended/prepended values, with checks, only if they need to be added to the tree.

I have another change lined up that depends on this deferral of the Closure evaluation to handle multiple appended/prepended values, but I chose to separate the two since this is more of a bugfix while the other is an enhancement.

@CodeWithDennis CodeWithDennis left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@CodeWithDennis CodeWithDennis merged commit a79b8b3 into CodeWithDennis:4.x May 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants