From 323724c4827f52740628543c1e1dde6162fabe44 Mon Sep 17 00:00:00 2001 From: gkrajniak Date: Wed, 18 Nov 2026 10:50:22 +0100 Subject: [PATCH 1/2] fix: register all themes for @ui5/webcomponents in the dashboard bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What changed - `mfp-wc-dashboard.js` now imports `@ui5/webcomponents/dist/generated/json-imports/Themes.js`, so every theme UI5 ships is registered for `@ui5/webcomponents`, as it already is for `@ui5/webcomponents-theming`. - New e2e spec `themes.e2e.ts` switches the OpenUI5 theme to `sap_horizon_dark`, `sap_horizon_hcb` and `sap_horizon_hcw`, waits for the theme to apply, opens edit mode and the Edit Cards dialog, and fails on any "not registered for package" console error. ## Why Only the default `sap_horizon` was registered for `@ui5/webcomponents`. In any other theme the console showed `Theme [sap_horizon_dark] not registered for package [@ui5/webcomponents]`, and the "Edit Home" and action buttons and the Edit Cards dialog were not themed. The theme-loader registry is module-local in the bundle, so consumers cannot register the themes themselves. ## Details - `@ui5/webcomponents-fiori` is not imported: the dashboard bundle contains no fiori components, so it never registers that package. - The full `@ui5/webcomponents/dist/Assets.js` is not used: it also inlines all i18n and CLDR data and grows the bundle to 16.3 MB. - Bundle size: 1,819,159 B → 2,720,920 B raw (+49.6%), 358,768 B → 476,595 B gzip (+32.8%). On-behalf-of: @SAP grzegorz.krajniak@sap.com Signed-off-by: gkrajniak --- e2e/specs/themes.e2e.ts | 82 +++++++++++++++++++ projects/webcomponents-dashboard/main.spec.ts | 1 + projects/webcomponents-dashboard/main.ts | 1 + 3 files changed, 84 insertions(+) create mode 100644 e2e/specs/themes.e2e.ts diff --git a/e2e/specs/themes.e2e.ts b/e2e/specs/themes.e2e.ts new file mode 100644 index 00000000..8d1a943f --- /dev/null +++ b/e2e/specs/themes.e2e.ts @@ -0,0 +1,82 @@ +import { openEditCardsDialog } from '../utils/edit-cards'; +import { enterEditMode, openHarness } from '../utils/harness'; +import { type Page, expect, test } from '@playwright/test'; + +const NON_DEFAULT_HORIZON_THEMES = [ + 'sap_horizon_dark', + 'sap_horizon_hcb', + 'sap_horizon_hcw', +] as const; + +type OpenUI5ThemingStub = { + __mfpSwitchTheme: (theme: string) => void; +}; + +async function stubOpenUI5(page: Page): Promise { + await page.addInitScript(() => { + let currentTheme = 'sap_horizon'; + const appliedHandlers: (() => void)[] = []; + const modules: Record = { + 'sap/ui/core/Theming': { + getTheme: () => currentTheme, + attachApplied: (handler: () => void) => appliedHandlers.push(handler), + }, + 'sap/base/i18n/Localization': { + getLanguageTag: () => 'en', + attachChange: () => undefined, + }, + }; + (window as unknown as { sap: unknown }).sap = { + ui: { + require: (deps: string[], callback: (module: unknown) => void) => + callback(modules[deps[0]]), + }, + }; + (window as unknown as OpenUI5ThemingStub).__mfpSwitchTheme = (theme) => { + currentTheme = theme; + appliedHandlers.forEach((handler) => handler()); + }; + }); +} + +function sapBackgroundColor(page: Page): Promise { + return page.evaluate(() => + getComputedStyle(document.documentElement).getPropertyValue( + '--sapBackgroundColor', + ), + ); +} + +test.describe('Themes', () => { + for (const theme of NON_DEFAULT_HORIZON_THEMES) { + test(`switching to ${theme} registers the theme for every UI5 package`, async ({ + page, + }) => { + const themeErrors: string[] = []; + page.on('console', (message) => { + if ( + message.type() === 'error' && + message.text().includes('not registered for package') + ) { + themeErrors.push(message.text()); + } + }); + await stubOpenUI5(page); + await openHarness(page); + const defaultBackground = await sapBackgroundColor(page); + + await page.evaluate( + (themeName) => + (window as unknown as OpenUI5ThemingStub).__mfpSwitchTheme(themeName), + theme, + ); + await expect + .poll(() => sapBackgroundColor(page)) + .not.toBe(defaultBackground); + await enterEditMode(page); + await openEditCardsDialog(page); + + expect(themeErrors).toEqual([]); + }); + } +}); diff --git a/projects/webcomponents-dashboard/main.spec.ts b/projects/webcomponents-dashboard/main.spec.ts index 897a4c33..ca966760 100644 --- a/projects/webcomponents-dashboard/main.spec.ts +++ b/projects/webcomponents-dashboard/main.spec.ts @@ -16,6 +16,7 @@ vi.mock('@ui5/webcomponents-base/dist/config/Language.js', () => ({ setLanguage, })); vi.mock('@ui5/webcomponents-theming/dist/Assets.js', () => ({})); +vi.mock('@ui5/webcomponents/dist/generated/json-imports/Themes.js', () => ({})); // The real declarative-ui barrel (which main.ts imports) pulls in the dashboard // component, which imports gridstack; gridstack fails to resolve under jsdom. diff --git a/projects/webcomponents-dashboard/main.ts b/projects/webcomponents-dashboard/main.ts index 75feb9aa..b96f2444 100644 --- a/projects/webcomponents-dashboard/main.ts +++ b/projects/webcomponents-dashboard/main.ts @@ -8,6 +8,7 @@ import { ignoreCustomElements } from '@ui5/webcomponents-base/dist/IgnoreCustomE import { setLanguage } from '@ui5/webcomponents-base/dist/config/Language.js'; import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme.js'; import '@ui5/webcomponents-theming/dist/Assets.js'; +import '@ui5/webcomponents/dist/generated/json-imports/Themes.js'; ignoreCustomElements('mfp'); From 1f83c2dffc597121ceb965d9932a12a1dfe57053 Mon Sep 17 00:00:00 2001 From: gkrajniak Date: Wed, 18 Nov 2026 10:58:23 +0100 Subject: [PATCH 2/2] fix: register all themes in the mfp-webcomponents bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## What changed `mfp-webcomponents.js` now imports the theme registrations for `@ui5/webcomponents-theming`, `@ui5/webcomponents` and `@ui5/webcomponents-fiori`, like `mfp-wc-dashboard.js` does. ## Why A page that loads both bundles runs two UI5 Web Components runtimes that share the theme setting and the `data-ui5-theme-properties` stylesheet. `mfp-webcomponents.js` registered no themes, so on the first switch to `sap_horizon_dark` it fell back to `sap_horizon`, wrote the light values into the shared stylesheet tagged as `sap_horizon_dark`, and the dashboard runtime then skipped its own update. The cards stayed light until the theme was switched a second time. ## Details - `@ui5/webcomponents-fiori` is included here because this bundle contains fiori components (for example the illustrated message). - Bundle size: 4,090,636 B → 5,934,115 B raw (+45.1%), 1,118,632 B → 1,343,766 B gzip (+20.1%). On-behalf-of: @SAP grzegorz.krajniak@sap.com Signed-off-by: gkrajniak --- projects/webcomponents/main.spec.ts | 7 +++++++ projects/webcomponents/main.ts | 3 +++ 2 files changed, 10 insertions(+) diff --git a/projects/webcomponents/main.spec.ts b/projects/webcomponents/main.spec.ts index d33c563b..24c17a03 100644 --- a/projects/webcomponents/main.spec.ts +++ b/projects/webcomponents/main.spec.ts @@ -17,6 +17,13 @@ vi.mock('@ui5/webcomponents-base/dist/IgnoreCustomElements.js', () => ({ ignoreCustomElements, })); +vi.mock('@ui5/webcomponents-theming/dist/Assets.js', () => ({})); +vi.mock('@ui5/webcomponents/dist/generated/json-imports/Themes.js', () => ({})); +vi.mock( + '@ui5/webcomponents-fiori/dist/generated/json-imports/Themes.js', + () => ({}), +); + // gridstack fails to resolve under jsdom; the real declarative-ui barrel pulls // it in transitively via the dashboard component. Stub it as the dashboard // spec does so the barrel can load. diff --git a/projects/webcomponents/main.ts b/projects/webcomponents/main.ts index ab63a8b2..8b55cfad 100644 --- a/projects/webcomponents/main.ts +++ b/projects/webcomponents/main.ts @@ -12,6 +12,9 @@ import { ResourceFormPatch, } from '@openmfp/webcomponents/declarative-ui'; import { ignoreCustomElements } from '@ui5/webcomponents-base/dist/IgnoreCustomElements.js'; +import '@ui5/webcomponents-fiori/dist/generated/json-imports/Themes.js'; +import '@ui5/webcomponents-theming/dist/Assets.js'; +import '@ui5/webcomponents/dist/generated/json-imports/Themes.js'; ignoreCustomElements('mfp');