filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.24k stars 2.96k forks source link

Builder bug with addActionBetween #12825

Open awcodes opened 6 months ago

awcodes commented 6 months ago

Package

filament/filament

Package Version

v3.2.40

Laravel Version

v11.7.0

Livewire Version

v3.4.12

PHP Version

PHP 8.2.8

Problem description

When adding items with the addBetweenAction once there are 4-5 items in the state the last item looses its alpine data somehow resulting in alpine throwing up in the console because ‘isCollapsed’ is undefined.

But then it reinitializes itself. But continues to not have the alpine data set on any following actions.

So if you click on collapse all they all collapse except that one. But the bug still happens regardless of collapsible or not. addAction doesn’t seem to trigger the issue, probably because the new item is always at the end of the state array.

Expected behavior

Blocks do not loose their alpine x-data properties.

Steps to reproduce

https://github.com/filamentphp/filament/assets/3596800/1d114bbf-035b-4fe7-907f-b338a3157a64

Reproduction repository

https://github.com/awcodes/builder-bug

Relevant log output

Alpine Expression Error: isCollapsed is not defined

Expression: "{ 'fi-collapsed overflow-hidden': isCollapsed }"

<li class="fi-fo-builder-item round…te/5 dark:ring-white/10" wire:key="PbiK2x6DQxx8eyCmZdri.dat…omponents\\Builder.item" x-data="{\n                     …                      }" x-init="() => console.log(`init …0b7-85aa-a6cee2bf0343`)" x-on:builder-expand.window="$event.detail === 'data.…& (isCollapsed = false)" x-on:builder-collapse.window="$event.detail === 'data.…&& (isCollapsed = true)" x-on:expand="isCollapsed = false" x-sortable-item="f2c27680-717b-40b7-85aa-a6cee2bf0343" x-bind:class="{ 'fi-collapsed overflow-hidden': isCollapsed }" data-has-alpine-state="true">
livewire.js:1123:13
Alpine Expression Error: isCollapsed is not defined

Expression: "{ '-rotate-180': isCollapsed }"

<li class="relative transition" x-on:click.stop="isCollapsed = !isCollapsed" x-bind:class="{ '-rotate-180': isCollapsed }">
livewire.js:1123:13
Alpine Expression Error: isCollapsed is not defined

Expression: "{ 'opacity-0 pointer-events-none': isCollapsed }"

<div class="transition" x-bind:class="{ 'opacity-0 pointer-events-none': isCollapsed }">
livewire.js:1123:13
Alpine Expression Error: isCollapsed is not defined

Expression: "{ 'opacity-0 pointer-events-none': ! isCollapsed }"

<div class="absolute inset-0 rotate-180 transition" x-bind:class="{ 'opacity-0 pointer-events-none': ! isCollapsed }">
livewire.js:1123:13
Alpine Expression Error: isCollapsed is not defined

Expression: "! isCollapsed"

<div class="fi-fo-builder-item-conte…-4 dark:border-white/10" x-show="! isCollapsed">

Donate 💰 to fund this issue

Fund with Polar

dmitry-udod commented 5 months ago

This is a really interesting bug, and it seems to occur in Livewire itself when you change the order of keys in an existing array. Livewire stops seeing the x-data directive, even though it is present in the HTML ¯_(ツ)_/¯. The problem disappears when you use a new key (UUID) for existing array items.

https://github.com/filamentphp/filament/assets/4639175/466f81ca-69e9-4839-aeaf-2a6fc89af058

I'm not sure if this is a valid solution for the bug, but it provides some additional information.