From 779ebc8d86572ccfd38c2a2d05de713a16d35f26 Mon Sep 17 00:00:00 2001 From: Vasily Strelyaev Date: Mon, 30 Sep 2024 15:10:34 +0300 Subject: [PATCH] fix: Angular throws an error when displaying the Trial Panel in SSR mode (T1248015) (#28112) --- .../license/license_validation.server.test.ts | 15 +++++++++++++++ .../__internal/core/license/trial_panel.client.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/devextreme/js/__internal/core/license/license_validation.server.test.ts b/packages/devextreme/js/__internal/core/license/license_validation.server.test.ts index 7e094d24d219..ec1b314f7387 100644 --- a/packages/devextreme/js/__internal/core/license/license_validation.server.test.ts +++ b/packages/devextreme/js/__internal/core/license/license_validation.server.test.ts @@ -18,4 +18,19 @@ describe('license token', () => { test('API inside trial_panel should not be triggered on the server', () => { expect(() => validateLicense('', '1.0.4')).not.toThrow(); }); + + test('API inside trial_panel should not be triggered in Angular, where HTMLElement is mocked', () => { + if (global.HTMLElement) { + throw Error('Wrong environment for this test!'); + } + + try { + // @ts-expect-error mocking HTMLElement with a symbol + global.HTMLElement = Symbol('HTMLElement mock'); + expect(() => validateLicense('', '1.0.4')).not.toThrow(); + } finally { + // @ts-expect-error removing the mock + delete global.HTMLElement; + } + }); }); diff --git a/packages/devextreme/js/__internal/core/license/trial_panel.client.ts b/packages/devextreme/js/__internal/core/license/trial_panel.client.ts index 9bd6b5c53bc1..5bf9446dc882 100644 --- a/packages/devextreme/js/__internal/core/license/trial_panel.client.ts +++ b/packages/devextreme/js/__internal/core/license/trial_panel.client.ts @@ -14,7 +14,7 @@ export interface CustomTrialPanelStyles { buttonStyles?: StylesMap; } -export const isClient = (): boolean => typeof HTMLElement !== 'undefined'; +export const isClient = (): boolean => typeof HTMLElement !== 'undefined' && typeof customElements !== 'undefined'; const SafeHTMLElement = isClient() ? HTMLElement