Skip to content

A platform for community discussion. Free, open, simple.

FIX: Reconcile restored design wizard homepage settings (#45345)

Penar Musarajfec37f397966
diff --git a/frontend/discourse/app/services/design-wizard.js b/frontend/discourse/app/services/design-wizard.js
index 29a3261e013..57273d3eceb 100644
--- a/frontend/discourse/app/services/design-wizard.js
+++ b/frontend/discourse/app/services/design-wizard.js
@@ -656,11 +656,19 @@ export default class DesignWizardService extends Service {
this.returnUrl = stored.returnUrl;
this.progressSaved = stored.progressSaved ?? false;
this.#snapshot = stored.snapshot;
- this.#originalHomepageSettings =
+ if (this.#snapshot) {
+ this.#snapshot.homepage_settings = this.#availableHomepageSettings(
+ this.#snapshot.homepage_settings
+ );
+ if (!this.#supportedHomepages.includes(this.#snapshot.homepage)) {
+ this.#snapshot.homepage = null;
+ }
+ }
+ this.#originalHomepageSettings = this.#availableHomepageSettings(
stored.originalHomepageSettings ??
- stored.snapshot?.homepage_settings ??
- this.data.homepage_settings ??
- {};
+ stored.snapshot?.homepage_settings ??
+ this.data.homepage_settings
+ );
// the intro is only ever shown once, before the first selection
this.showIntro = false;
this.themeId = stored.themeId;
@@ -669,10 +677,12 @@ export default class DesignWizardService extends Service {
this.palettesUserSelectable = stored.palettesUserSelectable;
this.bodyFont = stored.bodyFont;
this.headingFont = stored.headingFont;
- this.homepage =
- stored.homepage ?? this.#supportedHomepage(this.data.homepage);
- this.homepageSettings =
- stored.homepageSettings ?? this.data.homepage_settings ?? {};
+ this.homepage = this.#supportedHomepage(
+ stored.homepage ?? this.data.homepage
+ );
+ this.homepageSettings = this.#availableHomepageSettings(
+ stored.homepageSettings ?? this.data.homepage_settings
+ );
this.categoryPageStyle =
stored.categoryPageStyle ?? this.siteSettings.desktop_category_page_style;
this.welcomeBanner =
@@ -686,6 +696,15 @@ export default class DesignWizardService extends Service {
this.stepIndex = 0;
}
+ #availableHomepageSettings(settings) {
+ // A preview reload can resume after the available homepage options changed.
+ return Object.fromEntries(
+ Object.entries(settings ?? {}).filter(([name]) =>
+ Object.hasOwn(this.data.homepage_settings ?? {}, name)
+ )
+ );
+ }
+
#persistState() {
this.keyValueStore.set({
key: STATE_KEY,
diff --git a/frontend/discourse/tests/acceptance/design-wizard-test.gjs b/frontend/discourse/tests/acceptance/design-wizard-test.gjs
index fbefa6c7e1d..42fd373edee 100644
--- a/frontend/discourse/tests/acceptance/design-wizard-test.gjs
+++ b/frontend/discourse/tests/acceptance/design-wizard-test.gjs
@@ -326,6 +326,52 @@ acceptance("Design wizard - admin launch", function (needs) {
});
});
+ test("resuming drops homepage options that are no longer available", async function (assert) {
+ wizardData.homepage = "chat";
+ wizardData.homepage_settings = { chat_homepage_channel: "23" };
+ wizardData.additional_homepages = [
+ {
+ id: "chat",
+ name: "Chat",
+ path: "/categories",
+ settings: { chat_homepage_channel: "12" },
+ },
+ ];
+ sinon.stub(DiscourseURL, "redirectTo");
+
+ await visit("/admin");
+ await click(APPEARANCE_LAUNCH_BUTTON);
+ await click(".design-wizard__intro-start");
+
+ wizardData.additional_homepages = [];
+ wizardData.homepage_settings = {};
+ const wizard = this.owner.lookup("service:design-wizard");
+ await wizard.start({ resuming: true });
+ await wizard.saveProgress();
+
+ assert.strictEqual(savedPayloads.at(-1).homepage, "latest");
+ assert.strictEqual(savedPayloads.at(-1).homepage_settings, undefined);
+
+ await click(".design-wizard__next");
+ await click(".design-wizard__next");
+ await click('[data-homepage="categories"]');
+ await wizard.saveProgress();
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings,
+ undefined,
+ "selecting a homepage does not reintroduce unavailable original settings"
+ );
+
+ await click(".design-wizard__close");
+ await click(".dialog-footer .btn-danger");
+ assert.strictEqual(savedPayloads.at(-1).homepage, "");
+ assert.strictEqual(
+ savedPayloads.at(-1).homepage_settings,
+ undefined,
+ "reverting does not send unavailable snapshot settings"
+ );
+ });
+
["topics", "categories"].forEach((choice) => {
[false, true].forEach((resume) => {
test(`switching from Chat to ${choice} preserves the original channel${resume ? " after a preview reload" : ""}`, async function (assert) {