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

Extractor issues in Livewire Flux #17023

Closed
RobinMalfait opened this issue Mar 7, 2025 · 3 comments · Fixed by #17031
Closed

Extractor issues in Livewire Flux #17023

RobinMalfait opened this issue Mar 7, 2025 · 3 comments · Fixed by #17031
Assignees

Comments

@RobinMalfait
Copy link
Member

RobinMalfait commented Mar 7, 2025

@RobinMalfait hey we are having an issue with Livewire Flux since Tailwind v4.0.10 and I suspect it might be related to this PR. I tried compiling Tailwind locally to see if I could bisect exactly what PR/ commit is causing it, but I'm not smart enough to get it all running in a local repo 😆 so this PR is my best guess at what's causing the issue.

The problem we are having is we have a blade component for the sidebar <flux:sidebar /> and it looks something like this (simplified)

@php
if ($sidebarIsStashable) {
    $attributes = $attributes->merge([
        'x-init' => '$el.classList.add(\'-translate-x-full\'); $el.classList.add(\'transition-transform\')',
    ]);
}
@endphp

<div x-data {{ $attributes->class('border-r w-64 p-4 min-h-dvh max-h-dvh top-0 fixed left-0') }}>
    {{ $slot }}
</div>

Since the changes in Tailwind v4.0.10, the styles -translate-x-full and transition-transform which are inside the conditionally added x-init are not being compiled by Tailwind and our sidebar is not being hidden.

If I add those classes in another file though (or somewhere else in this file), they get compiled correctly and our sidebar is being hidden as expected.

I also experimented removing the backslashes from before the single quotes and everything works and compiles as expected.

'x-init' => "\$el.classList.add('-translate-x-full'); \$el.classList.add('transition-transform')",

Would you have any thoughts as to what might be causing that? It's causing issues because the new Laravel Livewire starter kit is using Flux and people's sidebars aren't hiding 😅

Thanks in advance!

Originally posted by @joshhanley in #16306 (comment)

@joshhanley
Copy link

Thanks @RobinMalfait! Let me know if you need any more information or want me to test anything. Happy to help as best as I can 🙂

RobinMalfait added a commit that referenced this issue Mar 7, 2025
…s expected (#17031)

This PR fixes an issue where candidates are not properly extractor when
they end in `\`. This can happen if you embed a programming language
like JS inside another language like PHP where you need to escape some
strings.

Here is an example of Livewire flux:
```blade
@php
if ($sidebarIsStashable) {
    $attributes = $attributes->merge([
        'x-init' => '$el.classList.add(\'-translate-x-full\'); $el.classList.add(\'transition-transform\')',
        //                                                ^                                            ^
    ]);
}
@endphp

<div x-data {{ $attributes->class('border-r w-64 p-4 min-h-dvh max-h-dvh top-0 fixed left-0') }}>
    {{ $slot }}
</div>
```
Where the `\'` is causing some issues.

Another solution might be to add a custom pre processor for blade files
where we drop the escaped characters, but that felt overkill for now
because some escapes are still valid.

Fixes: #17023

# Test plan

1. Added a test to cover this case.
2. Existing tests still pass
@RobinMalfait
Copy link
Member Author

Alright this should be fixed by #17031 and will be available in the next release. Going to prepare a new release as we speak. /cc @joshhanley

@joshhanley
Copy link

@RobinMalfait legend! Thanks so much for that. Can confirm, pulled down Tailwind v4.0.12 and the Flux sidebar is happy. Thanks again for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants