From add966c63fc4c9916e204a0e30a0f0e7c3a62a60 Mon Sep 17 00:00:00 2001 From: scottdowne Date: Wed, 22 Mar 2023 21:41:50 +0000 Subject: [PATCH] Bug 1822503 - Pocket newtab fixing startup reset from happening during experiment load. r=nanj,mconley,barret Differential Revision: https://phabricator.services.mozilla.com/D173342 --- browser/components/newtab/lib/PrefsFeed.jsm | 24 ++++++++++++------- .../newtab/test/unit/lib/PrefsFeed.test.js | 11 +++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/browser/components/newtab/lib/PrefsFeed.jsm b/browser/components/newtab/lib/PrefsFeed.jsm index 7836490f79eb..fb50fe48c64e 100644 --- a/browser/components/newtab/lib/PrefsFeed.jsm +++ b/browser/components/newtab/lib/PrefsFeed.jsm @@ -89,15 +89,21 @@ class PrefsFeed { */ onPocketExperimentUpdated(event, reason) { const value = lazy.NimbusFeatures.pocketNewtab.getAllVariables() || {}; - this.store.dispatch( - ac.BroadcastToContent({ - type: at.PREF_CHANGED, - data: { - name: "pocketConfig", - value, - }, - }) - ); + // Loaded experiments are set up inside init() + if ( + reason !== "feature-experiment-loaded" && + reason !== "feature-rollout-loaded" + ) { + this.store.dispatch( + ac.BroadcastToContent({ + type: at.PREF_CHANGED, + data: { + name: "pocketConfig", + value, + }, + }) + ); + } } init() { diff --git a/browser/components/newtab/test/unit/lib/PrefsFeed.test.js b/browser/components/newtab/test/unit/lib/PrefsFeed.test.js index 13cdd7001f13..dff262735a64 100644 --- a/browser/components/newtab/test/unit/lib/PrefsFeed.test.js +++ b/browser/components/newtab/test/unit/lib/PrefsFeed.test.js @@ -177,6 +177,17 @@ describe("PrefsFeed", () => { }) ); }); + it("should not send a PREF_CHANGED actions when onPocketExperimentUpdated is called during startup", () => { + sandbox + .stub(global.NimbusFeatures.pocketNewtab, "getAllVariables") + .returns({ + prefsButtonIcon: "icon-new", + }); + feed.onPocketExperimentUpdated({}, "feature-experiment-loaded"); + assert.notCalled(feed.store.dispatch); + feed.onPocketExperimentUpdated({}, "feature-rollout-loaded"); + assert.notCalled(feed.store.dispatch); + }); it("should send a PREF_CHANGED actions when onExperimentUpdated is called", () => { sandbox.stub(global.NimbusFeatures.newtab, "getAllVariables").returns({ prefsButtonIcon: "icon-new",