From bd87d0764c430ceea57d8ec76e08db4b85799ced Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Sun, 26 Jul 2026 16:20:26 +0200 Subject: [PATCH 1/3] Theme browser: prevent previous navigation on first theme. --- src/js/_enqueues/wp/theme.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index 56107ee475057..6eea3fa3fcf15 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1338,6 +1338,12 @@ themes.view.Themes = wp.Backbone.View.extend({ // Get the current theme. model = self.collection.get( args[0] ); + + // Bail early if the current theme is the first one. + if ( self.collection.indexOf( model ) === 0 ) { + return; + } + // Find the previous model within the collection. previousModel = self.collection.at( self.collection.indexOf( model ) - 1 ); From 04fcd03ddca7f6bd91a00da20036bbbaf3e28d13 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Tue, 28 Jul 2026 16:00:40 +0200 Subject: [PATCH 2/3] Apply Copilot feedback. --- src/js/_enqueues/wp/theme.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index 6eea3fa3fcf15..5339a3011267a 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1334,13 +1334,15 @@ themes.view.Themes = wp.Backbone.View.extend({ */ previous: function( args ) { var self = this, - model, previousModel; + model, previousModel, index; // Get the current theme. model = self.collection.get( args[0] ); - // Bail early if the current theme is the first one. - if ( self.collection.indexOf( model ) === 0 ) { + index = self.collection.indexOf( model ); + + // Bail early if the current theme is the first one or the model does not exist. + if ( index <= 0 ) { return; } From 434efa77a4a70bb7fd57f73a16aa529bfe1859c3 Mon Sep 17 00:00:00 2001 From: Andrea Fercia Date: Tue, 28 Jul 2026 16:20:06 +0200 Subject: [PATCH 3/3] Reuse the computed index. --- src/js/_enqueues/wp/theme.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/_enqueues/wp/theme.js b/src/js/_enqueues/wp/theme.js index 5339a3011267a..9bb2c648c4128 100644 --- a/src/js/_enqueues/wp/theme.js +++ b/src/js/_enqueues/wp/theme.js @@ -1347,7 +1347,7 @@ themes.view.Themes = wp.Backbone.View.extend({ } // Find the previous model within the collection. - previousModel = self.collection.at( self.collection.indexOf( model ) - 1 ); + previousModel = self.collection.at( index - 1 ); if ( previousModel !== undefined ) {