Skip to content

Commit

Permalink
fix: Angular throws an error when displaying the Trial Panel in SSR m…
Browse files Browse the repository at this point in the history
…ode (T1248015) (#28112)
  • Loading branch information
VasilyStrelyaev authored Sep 30, 2024
1 parent 88d1f92 commit 779ebc8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 779ebc8

Please sign in to comment.