Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

russellxu's avatar

Anyone use this filament plugin solution-forest/filament-tree? It has some problem with front&back end interaction

Basicly this component of filament does is to create a list tree that you can drag them and resort them. I used it in my new project, but I found a problem, every time I changed the order of list and I click save, the order of the list briefly reverts, and after refreshing the page, it changes to the final order I want. It works but still a lit bit of annyoning.

I try to dive into the source code, the reason cause this problem I think is ,the list data is not maintained by Alpine.js, and every time there is a Livewire request, the front-end component gets re-rendered.

I want to fix this issue, but I'm new to TALL stack, anyone can give some clue, I'll be much appreciate.

Link of solution-forest/filament-tree: https://github.com/solutionforest/filament-tree

0 likes
1 reply
LaryAI's avatar
Level 58

To address the issue you're experiencing with the solution-forest/filament-tree plugin, where the list order briefly reverts before saving, you can consider the following approach:

Understanding the Problem

The problem seems to stem from the interaction between Livewire and Alpine.js. When a Livewire request is made, the component is re-rendered, which can cause the temporary reversion of the list order. This is because the state is not being maintained correctly between the front-end and back-end.

Solution Steps

  1. Persist State with Livewire: Ensure that the state of your list is being correctly managed by Livewire. You can do this by binding the list order to a Livewire property and updating it whenever the order changes.

  2. Use Alpine.js for Local State Management: Use Alpine.js to manage the local state of the list order. This can help maintain the order on the front-end until the Livewire request completes.

  3. Debounce Livewire Requests: To prevent multiple rapid requests from causing issues, you can debounce the Livewire requests. This means only sending a request after a certain period of inactivity.

  4. Update the Component: Modify the component to ensure that the list order is updated both on the front-end and back-end consistently.

Example Code

Here's a basic example of how you might implement these changes:

// In your Livewire component
public $listOrder = [];

public function mount()
{
    // Initialize the list order from the database or other source
    $this->listOrder = $this->getInitialOrder();
}

public function updateOrder($newOrder)
{
    $this->listOrder = $newOrder;
    // Save the new order to the database
    $this->saveOrderToDatabase($newOrder);
}
<!-- In your Blade view -->
<div x-data="{ order: @entangle('listOrder') }">
    <ul>
        <template x-for="item in order" :key="item.id">
            <li x-text="item.name"></li>
        </template>
    </ul>

    <button @click="Livewire.emit('updateOrder', order)">Save Order</button>
</div>

Additional Tips

  • Check for Updates: Ensure you are using the latest version of the filament-tree plugin, as updates may have addressed this issue.
  • Consult Documentation: Review the plugin's documentation for any specific instructions on handling state with Livewire and Alpine.js.
  • Community Support: Consider reaching out to the community or the plugin's repository for additional support or to report the issue.

By managing the state effectively between Alpine.js and Livewire, you should be able to resolve the issue of the list order reverting temporarily.

Please or to participate in this conversation.