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
18.08k stars 2.83k forks source link

TernaryFilter null state is broken after refreshing and reseting filters #8073

Closed Plytas closed 1 year ago

Plytas commented 1 year ago

Package

filament/filament

Package Version

v3.0.34

Laravel Version

v10.20.0

Livewire Version

v3.0.0

PHP Version

PHP 8.2.7

Problem description

Ran into issue with TernaryFilter, which also applies to TrashedFilter that's present in https://github.com/filamentphp/demo. This only started breaking since version 3.0.28 when filter query params were introduced. This does not happen on https://demo.filamentphp.com because it's still on version 3.0.27.

Refreshing a page with filters enabled and then trying to reset filters will put null in query parameter causing filter to treat it as true.

Recording of this issue:

https://github.com/filamentphp/filament/assets/17316322/fe7966fe-e61b-4835-8009-75025c6ba887

Notice that when applying With deleted records there's a first row Dr. Dustin ... that's actually soft deleted. After reseting filters and refreshing page the filter gets applied again. This does not happen if you don't refresh the page in step 5. In that case reseting filters removes query param completely. I believe what happens is that state value becomes a string "null" and it becomes true when being cast to bool.

Expected behavior

Expected filter reset to use null state.

Steps to reproduce

  1. Set up filament demo
  2. Upgrade to version 3.0.28 or above
  3. Open Customers index /shop/customers
  4. Enable filter With deleted records
  5. Refresh the page
  6. Click Reset button in filter form
  7. Observe that url query parameter has null for filter value
  8. Refresh the page
  9. Observe incorrect filter being applied.

Reproduction repository

https://github.com/Plytas/demo

Relevant log output

No response

github-actions[bot] commented 1 year ago

Hey @Plytas! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.

github-actions[bot] commented 1 year ago

Thank you for providing reproduction steps! Reopening the issue now.

archilex commented 1 year ago

@Plytas Hi. This is a known issue with Livewire. Follow along on this thread as well as temporary fix you can implement: https://github.com/filamentphp/filament/issues/7129

Plytas commented 1 year ago

Thanks you, will close this in favor of #7129