diff --git a/packages/core/rendering/core-rendering-server-internal/src/render_utils.test.ts b/packages/core/rendering/core-rendering-server-internal/src/render_utils.test.ts index aefe6e2287e4f..96a81976c23ad 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/render_utils.test.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/render_utils.test.ts @@ -61,7 +61,6 @@ describe('getStylesheetPaths', () => { darkMode: true, themeVersion: 'v8', baseHref: '/base-path/buildShaShort', - buildNum: 17, }) ).toMatchInlineSnapshot(` Array [ @@ -83,7 +82,6 @@ describe('getStylesheetPaths', () => { darkMode: false, themeVersion: 'v8', baseHref: '/base-path/buildShaShort', - buildNum: 69, }) ).toMatchInlineSnapshot(` Array [ diff --git a/packages/core/rendering/core-rendering-server-internal/src/render_utils.ts b/packages/core/rendering/core-rendering-server-internal/src/render_utils.ts index e8b9e8b76c5e8..f4ce68885ddb6 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/render_utils.ts +++ b/packages/core/rendering/core-rendering-server-internal/src/render_utils.ts @@ -46,11 +46,7 @@ export const getScriptPaths = ({ } }; -export const getCommonStylesheetPaths = ({ - baseHref, -}: { - baseHref: string; -}) => { +export const getCommonStylesheetPaths = ({ baseHref }: { baseHref: string }) => { const bundlesHref = getBundlesHref(baseHref); return [ `${bundlesHref}/kbn-ui-shared-deps-src/${UiSharedDepsSrc.cssDistFilename}`, @@ -62,11 +58,9 @@ export const getThemeStylesheetPaths = ({ darkMode, themeVersion, baseHref, - buildNum, }: { darkMode: boolean; themeVersion: UiSharedDepsNpm.ThemeVersion; - buildNum: number; baseHref: string; }) => { const bundlesHref = getBundlesHref(baseHref); diff --git a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx index a62780d058d1b..dcf7162b481f8 100644 --- a/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx +++ b/packages/core/rendering/core-rendering-server-internal/src/rendering_service.tsx @@ -125,7 +125,6 @@ export class RenderingService { mode: this.coreContext.env.mode, packageInfo: this.coreContext.env.packageInfo, }; - const buildNum = env.packageInfo.buildNum; const staticAssetsHrefBase = http.staticAssets.getHrefBase(); const basePath = http.basePath.get(request); const { serverBasePath, publicBaseUrl } = http.basePath; @@ -191,7 +190,6 @@ export class RenderingService { darkMode: mode, themeVersion, baseHref: staticAssetsHrefBase, - buildNum, }); const commonStylesheetPaths = getCommonStylesheetPaths({ baseHref: staticAssetsHrefBase, diff --git a/packages/core/theme/core-theme-browser-internal/src/theme_service.ts b/packages/core/theme/core-theme-browser-internal/src/theme_service.ts index 9871a25ee7eea..c02074be77c3b 100644 --- a/packages/core/theme/core-theme-browser-internal/src/theme_service.ts +++ b/packages/core/theme/core-theme-browser-internal/src/theme_service.ts @@ -6,8 +6,7 @@ * Side Public License, v 1. */ -import { Subject, ReplaySubject } from 'rxjs'; -import { shareReplay, takeUntil } from 'rxjs/operators'; +import { of } from 'rxjs'; import { _setDarkMode } from '@kbn/ui-theme'; import type { InjectedMetadataTheme } from '@kbn/core-injected-metadata-common-internal'; import type { InternalInjectedMetadataSetup } from '@kbn/core-injected-metadata-browser-internal'; @@ -22,45 +21,44 @@ export interface ThemeServiceSetupDeps { /** @internal */ export class ThemeService { - private theme$ = new ReplaySubject(1); - private stop$ = new Subject(); - + private contract?: ThemeServiceSetup; private themeMetadata?: InjectedMetadataTheme; private stylesheets: HTMLLinkElement[] = []; public setup({ injectedMetadata }: ThemeServiceSetupDeps): ThemeServiceSetup { - const theme = injectedMetadata.getTheme(); - this.themeMetadata = theme; + const themeMetadata = injectedMetadata.getTheme(); + this.themeMetadata = themeMetadata; - if (theme.darkMode === 'system' && browsersSupportsSystemTheme()) { - const darkMode = systemThemeIsDark(); - this.applyTheme(darkMode); - // onSystemThemeChange((mode) => this.applyTheme(mode)); + let theme: CoreTheme; + if (themeMetadata.darkMode === 'system' && browsersSupportsSystemTheme()) { + theme = { darkMode: systemThemeIsDark() }; } else { - const darkMode = theme.darkMode === 'system' ? false : theme.darkMode; - this.applyTheme(darkMode); + const darkMode = themeMetadata.darkMode === 'system' ? false : themeMetadata.darkMode; + theme = { darkMode }; } - return { - theme$: this.theme$.pipe(takeUntil(this.stop$), shareReplay(1)), + this.applyTheme(theme); + + this.contract = { + getTheme: () => theme, + theme$: of(theme), }; + + return this.contract; } public start(): ThemeServiceStart { - if (!this.themeMetadata) { + if (!this.contract) { throw new Error('setup must be called before start'); } - return { - theme$: this.theme$.pipe(takeUntil(this.stop$), shareReplay(1)), - }; + return this.contract; } - public stop() { - this.stop$.next(); - } + public stop() {} - private applyTheme(darkMode: boolean) { + private applyTheme(theme: CoreTheme) { + const { darkMode } = theme; this.stylesheets.forEach((stylesheet) => { stylesheet.remove(); }); @@ -75,7 +73,6 @@ export class ThemeService { _setDarkMode(darkMode); updateKbnThemeTag(darkMode); - this.theme$.next({ darkMode }); } }