Dataviews Filter: Showing error when sort-by filter changes to Status#72252
Dataviews Filter: Showing error when sort-by filter changes to Status#72252levinbaria wants to merge 1 commit intoWordPress:trunkfrom
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
t-hamano
left a comment
There was a problem hiding this comment.
Thanks for the PR!
This pull request certainly solves the problem, but I believe it's the developer's responsibility to define the appropriate type and value for each field. Otherwise, it becomes impossible to detect errors in invalid fields.
I think it's best to move forward with #72648.
|
Closing in favor of #72648 |
What?
Fix a runtime TypeError when sorting DataViews by fields that can produce non-string or missing values. Specifically: prevent "TypeError: a.localeCompare is not a function" by hardening the comparators used for sorting in dataviews field types and the fallback comparator.
Why?
When sorting, some comparators called
localComparedirectly on values that could be undefined, null, or non-string. CallinglocalCompareon a non-string throws a TypeError and breaks the UI when users change sort settings (reported when sorting by Status in dataviews). This PR makes the sorting comparators robust so they never calllocaleCompareon a non-string.How?
For field types that can reasonably return non-strings or undefined (text, email, url, and the fallback field-type), comparator code now coerces values to strings before calling
localeCompare:Testing Instructions
Statusor any other fields.Testing Instructions for Keyboard
Screenshots or screencast
error.mp4