spatie / laravel-blade-comments

Add debug comments to your rendered output
https://freek.dev/2500-a-laravel-package-to-quickly-see-which-html-is-rendered-by-which-blade-view
MIT License
159 stars 9 forks source link

[Bug]: SectionCommenter breaks classes injected in a @yield #13

Closed bjhijmans closed 10 months ago

bjhijmans commented 1 year ago

What happened?

We have a layout that lets you insert classes into the body using @yield and @section. But the section commenter makes the classes invalid.

How to reproduce the bug

Have a page with a @yield for a class:

<body class="@yield('body-class')">
</body>

Then add a page that extends that layout and try to add classes:

@section('body-class', 'gray-bg login-page')

The resulting tag is as follows:

<body class="<!-- Start section: body-class -->gray-bg login-page<!-- End section: body-class -->">

Due to the placement of the comment tag, my browser (at least chrome and firefox) doesn't recognize the gray-bg and login-page classes. Adding a space before and after the HTML comments fixes the issue. Maybe there should always be a space around the comments?

Package Version

1.0.3

PHP Version

8.1.x

Laravel Version

10.13.0

Which operating systems does with happen with?

Linux

Notes

No response

timvandijck commented 1 year ago

This is relatively similar to the problem described in #11.

I'll defenitly be looking at implementing a blacklist feature as described there, and probably try to add a set of sensible default situations where to never add an HTML comment.

spatie-bot commented 10 months ago

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.