From 6d3b86868ed9a41c2c585af5a7b011e212e93614 Mon Sep 17 00:00:00 2001 From: umesh Date: Thu, 26 Nov 2026 18:16:07 +0530 Subject: [PATCH 1/2] Themes: Fix stale Favorites state when switching to Feature Filters. 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. --- src/js/_enqueues/wp/theme.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index dabd64cc6c6ba..3f5913202ab56 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1908,6 +1908,24 @@ themes.view.Installer = themes.view.Appearance.extend({ username: username }, success: function () { + var queries = that.collection.queries; + + /* + * Drop cached favorites results, such as the empty one from before a + * username was saved, so they are not served for the previous username. + */ + that.collection.queries = _.reject( queries, function( query ) { + return 'favorites' === query.request.browse; + } ); + + /* + * The Favorites tab queries without a user (the server uses the saved + * one), so use the same request to share its cache entry. + */ + if ( username ) { + request = { browse: 'favorites' }; + } + // Get the themes by sending Ajax POST request to api.wordpress.org/themes // or searching the local cache. that.collection.query( request ); @@ -1975,6 +1993,12 @@ themes.view.Installer = themes.view.Appearance.extend({ themes.router.navigate( themes.router.baseUrl( '' ) ); // Toggle the feature filters view. $body.toggleClass( 'show-filters' ); + + // Opening the filters leaves the previous section's results behind, so drop the stale message. + if ( $body.hasClass( 'show-filters' ) ) { + $body.removeClass( 'no-results' ); + } + // Toggle the `aria-expanded` button attribute. $toggleButton.attr( 'aria-expanded', $body.hasClass( 'show-filters' ) ); }, From 8e8dbcf15466c1484dad45237909034fe84b5f21 Mon Sep 17 00:00:00 2001 From: umesh Date: Fri, 27 Nov 2026 19:20:05 +0530 Subject: [PATCH 2/2] Themes: Fix stale message and count when switching to Feature Filters. 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. --- src/js/_enqueues/wp/theme.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index 3f5913202ab56..05afc16a648bc 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1783,6 +1783,8 @@ themes.view.Installer = themes.view.Appearance.extend({ // Bail if this is already active. if ( $el.hasClass( this.activeClass ) ) { + // The filters closed without a new query, so bring back the count. + this.restoreThemeCount(); return; } @@ -1977,10 +1979,25 @@ themes.view.Installer = themes.view.Appearance.extend({ }); }, + /** + * Restores the theme count that was reset when the filters were opened. + * + * Used when the filters close without a new query, so the results + * that are shown again keep their count. + */ + restoreThemeCount: function() { + var $count = $( '.wrap .theme-count' ); + + if ( undefined !== $count.data( 'previous-count' ) ) { + $count.text( $count.data( 'previous-count' ) ).removeData( 'previous-count' ); + } + }, + // Toggle the full filters navigation. moreFilters: function( event ) { var $body = $( 'body' ), - $toggleButton = $( '.drawer-toggle' ); + $toggleButton = $( '.drawer-toggle' ), + $count = $( '.wrap .theme-count' ); event.preventDefault(); @@ -1994,9 +2011,16 @@ themes.view.Installer = themes.view.Appearance.extend({ // Toggle the feature filters view. $body.toggleClass( 'show-filters' ); - // Opening the filters leaves the previous section's results behind, so drop the stale message. + /* + * Opening the filters hides the previous section's results, so drop its stale + * message and reset the theme count. Closing them without applying a filter + * shows those results again, so restore the count. + */ if ( $body.hasClass( 'show-filters' ) ) { $body.removeClass( 'no-results' ); + $count.data( 'previous-count', $count.text() ).text( 0 ); + } else { + this.restoreThemeCount(); } // Toggle the `aria-expanded` button attribute.