Skip to content

Commit 40fc2c5

Browse files
committed
fix another crash that can occur during loading of a ui5 site
1 parent 83cd559 commit 40fc2c5

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/browser/common.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ declare global {
3232
* handling for if the page is not ui5.
3333
* sap webgui also uses a global sap object so we need to check for sap.ui specifically
3434
*/
35-
export const isUi5 = () => typeof sap !== 'undefined' && typeof sap.ui !== 'undefined'
35+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition -- the types don't account for this but any of these could be undefined if the ui5 runtime is partially loaded
36+
export const isUi5 = () => typeof sap !== 'undefined' && sap.ui?.core !== undefined
3637

3738
export class Ui5SelectorEngineError extends Error {
3839
constructor(selector: string, error: unknown) {

src/browser/css.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ const querySelector = (root: Element | Document, selector: AstSelector): Element
6161
}
6262

6363
const controls =
64-
// eslint-disable-next-line detachhead/suggestions-as-errors, @typescript-eslint/no-unnecessary-condition -- using the deprecated registry since we still want to support older ui5 versions, seems this can be undefined if the page is in the middle of loading
65-
sap.ui.core.Element?.registry.filter((element) => {
64+
// eslint-disable-next-line detachhead/suggestions-as-errors, @typescript-eslint/no-unnecessary-condition -- using the deprecated registry since we still want to support older ui5 versions, seems any part of this can be undefined if the page is in the middle of loading
65+
sap.ui?.core?.Element?.registry.filter((element) => {
6666
if (
6767
(rule.tag?.type === 'TagName' &&
6868
rule.tag.name !== element.getMetadata().getName() &&

tests/css.spec.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,15 @@ test.describe('no ui5 site', () => {
142142
})
143143
await expect(page.locator('ui5_css=m.Button')).toHaveCount(0)
144144
})
145+
test('ui5 runtime is partially loaded', async ({ page }) => {
146+
await page.evaluate(() => {
147+
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/43434
148+
window.sap = {
149+
ui: {},
150+
}
151+
})
152+
await expect(page.locator('ui5_css=m.Button')).toHaveCount(0)
153+
})
145154
})
146155
test.describe('unsupported syntax', () => {
147156
test('comparitors', ({ page }) =>

0 commit comments

Comments
 (0)