diff --git a/packages/base/brand-guide.gts b/packages/base/brand-guide.gts index daa5957ce5..2e1b982d94 100644 --- a/packages/base/brand-guide.gts +++ b/packages/base/brand-guide.gts @@ -75,6 +75,7 @@ class BrandGuideIsolated extends Component { diff --git a/packages/base/default-templates/theme-dashboard.gts b/packages/base/default-templates/theme-dashboard.gts index d00770b237..dd1546d60b 100644 --- a/packages/base/default-templates/theme-dashboard.gts +++ b/packages/base/default-templates/theme-dashboard.gts @@ -18,7 +18,12 @@ import { FieldContainer, BoxelInput, } from '@cardstack/boxel-ui/components'; -import { bool, cn, themeScopedCss } from '@cardstack/boxel-ui/helpers'; +import { + bool, + cn, + themeScope, + themeScopedCss, +} from '@cardstack/boxel-ui/helpers'; import { DEFAULT_THEME_SCALE } from '../structured-theme-variables'; @@ -1072,11 +1077,20 @@ export class ThemeDashboard extends GlimmerComponent<{ version?: string; isDarkMode?: boolean; themeCss?: string | null; + themeId?: string | null; }; Blocks: { default: []; header: []; navBar: [] }; Element: HTMLElement; }> { - private themeScopeId = guidFor(this); + // Content-derived rather than guidFor: this markup can be persisted as + // prerendered HTML, where the scoped rules are page-global. Equal scopes + // are only safe when their declarations are equal too, which the theme id + // plus content hash guarantees; a per-process guid can repeat across + // prerender jobs with different themes. The guid fallback only covers + // unsaved theme cards previewing their own CSS, which are never persisted. + private get themeScopeId() { + return themeScope(this.args.themeId, this.args.themeCss) ?? guidFor(this); + } // The data-theme wrapper drives the preview's light/dark toggle through the // ambient `--boxel-color-scheme` signal, flipping the semantic tokens to the @@ -1097,7 +1111,10 @@ export class ThemeDashboard extends GlimmerComponent<{ > {{#if @themeCss}} {{! template-lint-disable require-scoped-style }} - {{! template-lint-enable require-scoped-style }} diff --git a/packages/base/detailed-style-reference.gts b/packages/base/detailed-style-reference.gts index 277ba03b82..5a82663fe3 100644 --- a/packages/base/detailed-style-reference.gts +++ b/packages/base/detailed-style-reference.gts @@ -143,6 +143,7 @@ class Isolated extends Component {