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

Opening the Filter Menu sometimes causes a refresh #6424

Open
tylernathanreed opened this issue Jun 12, 2024 · 2 comments
Open

Opening the Filter Menu sometimes causes a refresh #6424

tylernathanreed opened this issue Jun 12, 2024 · 2 comments
Labels
Milestone

Comments

@tylernathanreed
Copy link

tylernathanreed commented Jun 12, 2024

  • Laravel Version: 10.48.12
  • Nova Version: 4.34.2
  • PHP Version: 8.2.13

Description:

Opening the Filter Menu can cause a refresh when the backing value changes from a string to an integer, even if the value is effectively the same (e.g. 2 vs "2").

Detailed steps to reproduce the issue on a fresh Nova installation:

Follow these steps:

  1. Create a resource
  2. Add a filterable select field
  3. Have the select field's option values be integers
  4. In the UI, filter to any option
  5. Refresh the page (this forces the filter values to source from the URL string)
  6. Open the filter menu
  7. The resource table will refresh just by opening the menu, despite not having selected anything yet

Repository:
https://github.com/tylernathanreed/nova-issues/pull/1/files

Video:

Nova.6424.mp4

Root Cause

It took me awhile to figure this one out, but the root cause was the filter value changing from a string to an integer (e.g. "2" to 2). When a value is initially selected, the value ends up being a string. However, when the value is initialized from a string, the Filter/SelectField component finds the option matching the string-based value, and assigns option.value to this.value, where option.value was actually an integer.

I was able to hack in a fix by modifying the source code for Filter/SelectField's watch:selectedOption function, and changing this.value = option.value to this.value = String(option.value). There may be edge cases that need to be explored, but that solution definitely solved my problem.

@crynobone crynobone added the needs more info More information is required label Jun 13, 2024
@crynobone
Copy link
Member

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

@tylernathanreed
Copy link
Author

@crynobone

I've created a repository for you, and I've linked a pull request (to my own repository) that shows you the files I added on top of the default Nova installation.

I've also attached a video demonstrating the bug.

@crynobone crynobone added the pending Issues that are pending triage label Jun 27, 2024
@crynobone crynobone added next and removed needs more info More information is required pending Issues that are pending triage labels Jul 23, 2024
@crynobone crynobone added this to the 5.x milestone Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants