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
Passing a name attribute into a component scoped slot will cause the supplied name attribute to be missing in the scoped slot's attribute variable. This only occurs when name is the first attribute passed in.
ComponentTagCompiler::compileSlots is responsible for this. My understanding is that slots used to be named by passing a name attribute. This is no longer the documented way of creating a named slot but this check is still in the code to support backwards compatibility.
Because name is a very common HTML attribute used on forms, this gotcha can catch you out very easily and result in some unexpected behaviour of the name attribute just disappearing - which can cause forms to break
Possible Solutions
Document this behaviour in the docs
Deprecate naming slots using the name attribute and drop support for in the next major release
Make the name attribute available in the scoped slot's attribute variable
Steps To Reproduce
Create a component in resources/views/components/input.blade.php
Made a pull request clarifying this situation: laravel/docs#8788. No worries, if Taylor thinks that this issue should be addressed for Laravel 10 or 11, I will follow up. Thanks!
Laravel Version
9.52.7
PHP Version
8.2.5
Database Driver & Version
No response
Description
Passing a
name
attribute into a component scoped slot will cause the supplied name attribute to be missing in the scoped slot's attribute variable. This only occurs whenname
is the first attribute passed in.ComponentTagCompiler::compileSlots
is responsible for this. My understanding is that slots used to be named by passing a name attribute. This is no longer the documented way of creating a named slot but this check is still in the code to support backwards compatibility.Because
name
is a very common HTML attribute used on forms, this gotcha can catch you out very easily and result in some unexpected behaviour of the name attribute just disappearing - which can cause forms to breakPossible Solutions
name
attribute and drop support for in the next major releasename
attribute available in the scoped slot's attribute variableSteps To Reproduce
Create a component in
resources/views/components/input.blade.php
Render the component, passing a name attribute as the first first attribute
Observe, the
name
does not get rendered in the slot's attributesMoving the name attribute to not being the first attribute will make the name attribute render
Outputs
The text was updated successfully, but these errors were encountered: