Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using @aware does not remove attributes from $attributes #54276

Closed
adwiv opened this issue Jan 20, 2025 · 3 comments
Closed

Using @aware does not remove attributes from $attributes #54276

adwiv opened this issue Jan 20, 2025 · 3 comments

Comments

@adwiv
Copy link

adwiv commented Jan 20, 2025

Laravel Version

11.37.0

PHP Version

8.2.15

Database Driver & Version

MariaDB 10.11.1 on macOS Intel

Description

When defining an anonymous component with parent accessor using @aware directive, we can override the parent attribute by passing the value in child component.

However, that attribute is not removed from the $attributes list.

Ideally, all attributes defined in the @aware directive should be removed from $attributes alongwith the attributes defined in @props

Steps To Reproduce

Using the example from Documentation - Blade#accessing-parent-data

This code:

<x-menu color="purple">
  <x-menu.item>...</x-menu.item>
  <x-menu.item color="red">...</x-menu.item>
</x-menu>

generates the following html (formatted for clarity)

<ul class="bg-purple-200">
    <li class="text-purple-800">...</li>
    <li class="text-red-800" color="red">...</li>
</ul>

As we can see, color="red" remains in the attribute list for second list item.

Only way to remove it from the attribute list is to define @props directive along with @aware, which seems redundant.

@crynobone
Copy link
Member

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

@adwiv
Copy link
Author

adwiv commented Jan 21, 2025

https://github.com/adwiv/laravel-bug-report-54276

<!-- View file -->
<x-menu color="purple">
    <x-menu.item>Home</x-menu.item>
    <x-menu.item color="red">About</x-menu.item>
</x-menu>
<!-- Expected output -->
<ul class="bg-purple-200">
    <li class="text-purple-800">Home</li>
    <li class="text-red-800">About</li>
</ul>
<!-- Actual output -->
<ul class="bg-purple-200">
    <li class="text-purple-800">Home</li>
    <li class="text-red-800" color="red">About</li>
</ul>

Issue Description:
When using the @aware directive to define the color attribute in item.blade.php, the attribute remains in the AttributeBag instead of being removed.

Current Workaround:
The attribute can be properly handled by declaring it in both @props and @aware directives. However, it seems redundant to redeclare the attribute in @props

Expected Behavior:
The @aware directive should automatically remove the declared attributes from the AttributeBag.

@crynobone
Copy link
Member

crynobone commented Jan 22, 2025

Image

Sorry, we don't consider this a bug but you are more than welcome to try and submit PR to improve this.

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

No branches or pull requests

2 participants