A platform for community discussion. Free, open, simple.
UX: Show a helpful error when theme preview fails (#35034)
David Taylor519335528ff9
diff --git a/app/assets/javascripts/discourse/app/components/global-notice.gjs b/app/assets/javascripts/discourse/app/components/global-notice.gjsindex 84292b27a7f..8f5a832e791 100644--- a/app/assets/javascripts/discourse/app/components/global-notice.gjs+++ b/app/assets/javascripts/discourse/app/components/global-notice.gjs@@ -8,6 +8,7 @@ import { tagName } from "@ember-decorators/component";import DButton from "discourse/components/d-button";import cookie, { removeCookie } from "discourse/lib/cookie";import { bind } from "discourse/lib/decorators";+import { currentThemeId } from "discourse/lib/theme-selector";import { DeferredTrackedSet } from "discourse/lib/tracked-tools";import { i18n } from "discourse-i18n";@@ -119,13 +120,27 @@ export default class GlobalNotice extends Component {);}- if (this.router.currentRoute?.queryParams?.preview_theme_id) {- notices.push(- Notice.create({- text: i18n("theme_preview_notice"),- id: "theme-preview",- })- );+ const previewThemeId =+ this.router.currentRoute?.queryParams?.preview_theme_id;+ if (previewThemeId) {+ if (currentThemeId() === parseInt(previewThemeId, 10)) {+ notices.push(+ Notice.create({+ text: i18n("theme_preview_notice"),+ id: "theme-preview",+ })+ );+ } else {+ notices.push(+ Notice.create({+ text: i18n("theme_preview_failed"),+ id: "theme-preview-failed",+ options: {+ level: "error",+ },+ })+ );+ }}if (this.siteSettings.disable_emails === "yes") {diff --git a/config/locales/client.en.yml b/config/locales/client.en.ymlindex 3d09a2c3333..ed15b24730e 100644--- a/config/locales/client.en.yml+++ b/config/locales/client.en.yml@@ -5174,6 +5174,7 @@ en:enabled: "Safe mode is enabled, to exit safe mode close this browser window"theme_preview_notice: "You are currently previewing a theme, close this browser tab or window to return to your normal site configuration."+ theme_preview_failed: "Failed to preview theme because it doesn't exist, or you don't have permission to access it."image_removed: "(image removed)"