You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I recently noticed behavior with Laravel's blade components that I found very unintuitive. If I'm rendering a component inside another component, properties passed to the parent component are automatically passed to the child component.
Here is an example of what is happening.
top-level blade:
<x-confirmation-form id="confirmation-form"/>
The confirmation form class has no constructor arguments.
What happens is that any component with named properties gets them filled from $attributes if it exists. So when we use a component inside a component, it takes the id from the ComponentAttributeBag$attributes and passes it as a parameter to the Input class. This behavior isn't documented anywhere.
This is the code from CompilesComponents that does it:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I recently noticed behavior with Laravel's blade components that I found very unintuitive. If I'm rendering a component inside another component, properties passed to the parent component are automatically passed to the child component.
Here is an example of what is happening.
top-level blade:
The confirmation form class has no constructor arguments.
confirmation-form:
Input component:
and blade:
What I expected the rendered html to look like:
But what I got instead was this:
What happens is that any component with named properties gets them filled from
$attributes
if it exists. So when we use a component inside a component, it takes the id from theComponentAttributeBag
$attributes
and passes it as a parameter to theInput
class. This behavior isn't documented anywhere.This is the code from
CompilesComponents
that does it:I think it makes no sense that it works this way, but it looks like it was done on purpose and isn't a bug? Does this make sense to anyone?
Beta Was this translation helpful? Give feedback.
All reactions