Skip to content

Themes: Fix stale Favorites state when switching to Feature Filters. - #16265

Open
umeshnevase wants to merge 2 commits into
WordPress:trunkfrom
umeshnevase:fix/theme-install-stale-no-themes-message
Open

umeshnevase wants to merge 2 commits into
WordPress:trunkfrom
umeshnevase:fix/theme-install-stale-no-themes-message

Conversation

@umeshnevase

Copy link
Copy Markdown

On Appearance > Add Themes, switching between the Favorites tab and the Feature Filter drawer leaves the theme installer in a wrong state. This PR fixes two problems in src/js/_enqueues/wp/theme.js.

1. Stale "No themes found" message under Feature Filters

An empty Favorites result adds the no-results class to <body>. Opening the Feature Filter drawer doesn't run a new query, so the class is never removed, and the "No themes found. Try a different search." message stays visible under the drawer.

moreFilters() now removes no-results when the drawer opens.

2. Fetched favorites disappear after switching tabs

The Favorites tab queries { browse: 'favorites' }, and the server fills in the saved username. Opening Favorites before a username is saved caches an empty result under that key. Fetching by username caches the themes under a different key, { browse: 'favorites', user }. After opening Feature Filter and returning to Favorites, the tab hits the stale empty cache entry and shows nothing, until the page is refreshed.

saveUsername() now:

  • drops cached favorites queries after the username is saved, so a stale or previous-username result is never served, and
  • queries with { browse: 'favorites' } when a username is entered, so the fetched themes share the cache entry the tab uses.

The Favorites username form behaves as before, and it shows again after switching back to the tab.

Testing instructions

  1. Go to Appearance > Add Themes (as a user with no saved WordPress.org username, or clear the wporg_favorites user option).
  2. Click Favorites, then Feature Filter. The "No themes found" message should no longer appear under the drawer.
  3. Click Favorites again. The username form should be shown.
  4. Enter a WordPress.org username that has favorite themes and click Get Favorites. The themes should be listed.
  5. Click Feature Filter, then Favorites. The fetched themes should still be listed, without a page refresh.
  6. Optionally, apply a filter, then go back to Favorites, and change the username to confirm the new username's themes load instead of the old ones.

Trac ticket: https://core.trac.wordpress.org/ticket/66833

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Reproducing the issue, diagnosing the causes, and drafting the fix and this description. I reviewed the changes and tested them manually in the browser.

After Fix:

after-message-fix

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

On Appearance > Add Themes, switching between the Favorites tab and the Feature Filter drawer left the theme installer in an inconsistent state:

* A "No themes found" message from an empty Favorites result stayed visible under the Feature Filter drawer, because the `no-results` body class was only cleared when a new query started. Opening the drawer now clears it.
* Fetched favorites disappeared after opening Feature Filter and returning to Favorites. The tab queries `{ browse: 'favorites' }`, but fetching by username cached the result under `{ browse: 'favorites', user }`. The tab therefore hit the empty entry cached before a username was saved. Saving a username now drops stale cached favorites queries and uses the same request as the tab, so fetched themes are kept without a page refresh.

The Favorites username form is left unchanged, so it still shows after switching back to the tab.
@github-actions

github-actions Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs.

Core Committers: Use this line as a base for the props when committing in SVN:

Props umeshnevase, pedrofigueroa1989.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub or WordPress.org user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@mardelnet mardelnet left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your code changes look good to me and fix the issue.

I also noticed that the Theme Count is not updated when switching from any tab to the "Feature Filter" tab, so for example, if the counter displays "2011" in the Block Themes tab, it keeps showing "2011" when the "Feature Filter" tab is activated. In my opinion, it should be reset and go back to zero.

Something like this might work from moreFilters(): $( '.wrap .theme-count' ).text( 0 );

On Appearance > Add Themes, opening the Feature Filter drawer hides the current results but leaves their state on screen, and switching back could lose the count.

* The "No themes found" message from an empty Favorites result stayed visible under the drawer, because the `no-results` body class was only cleared when a new query started. Opening the drawer now clears it.
* The theme count kept showing the previous tab's total (for example 2011 from Block Themes) while no themes were shown. Opening the drawer now resets it to 0. The previous count is restored when the drawer is closed without applying a filter, including when the already-active tab is clicked, which closes the drawer without running a query.
@umeshnevase

Copy link
Copy Markdown
Author

Your code changes look good to me and fix the issue.

I also noticed that the Theme Count is not updated when switching from any tab to the "Feature Filter" tab, so for example, if the counter displays "2011" in the Block Themes tab, it keeps showing "2011" when the "Feature Filter" tab is activated. In my opinion, it should be reset and go back to zero.

Something like this might work from moreFilters(): $( '.wrap .theme-count' ).text( 0 );

Thank you @mardelnet for the review.
I've pushed a new commit to fix the theme count issue you reported. I fixed the count issue and tested it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants