Skip to content

Dataviews Filter: Showing error when sort-by filter changes to Status#72252

Closed
levinbaria wants to merge 1 commit intoWordPress:trunkfrom
levinbaria:fix/dataviews-sort
Closed

Dataviews Filter: Showing error when sort-by filter changes to Status#72252
levinbaria wants to merge 1 commit intoWordPress:trunkfrom
levinbaria:fix/dataviews-sort

Conversation

@levinbaria
Copy link
Contributor

@levinbaria levinbaria commented Oct 10, 2025

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 localCompare directly on values that could be undefined, null, or non-string. Calling localCompare on 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 call localeCompare on 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:

  • null/undefined -> '' (empty string)
  • else -> String(value)

Testing Instructions

  1. Go to the Templates --- Appearance->Editor->Templates
  2. Change the filter-> "Sort by" option to Status or any other fields.
  3. Observe the console: there should be no "TypeError: a.localeCompare is not a function". -- No UI breaks.
  4. Confirm sorting behaves sensibly: Ascending vs descending order toggles as expected.

Testing Instructions for Keyboard

Screenshots or screencast

error.mp4
Before After

@levinbaria levinbaria requested a review from oandregal as a code owner October 10, 2025 15:01
@github-actions
Copy link

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: levinbaria <levinbaria@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@levinbaria levinbaria marked this pull request as draft October 10, 2025 15:02
@levinbaria levinbaria marked this pull request as ready for review October 10, 2025 15:05
@github-project-automation github-project-automation bot moved this to 🔎 Needs Review in WordPress 6.9 Editor Tasks Oct 20, 2025
@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Feature] Templates API Related to API powering block template functionality in the Site Editor labels Oct 20, 2025
@t-hamano t-hamano linked an issue Oct 22, 2025 that may be closed by this pull request
6 tasks
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

cc @ramonjd @Mamaduka

@t-hamano
Copy link
Contributor

Closing in favor of #72648

@t-hamano t-hamano closed this Oct 24, 2025
@github-project-automation github-project-automation bot moved this from 🔎 Needs Review to ✅ Done in WordPress 6.9 Editor Tasks Oct 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Templates API Related to API powering block template functionality in the Site Editor [Type] Bug An existing feature does not function as intended

Projects

Development

Successfully merging this pull request may close these issues.

Sorting templates by status causes a persistent error in the template editor

2 participants