ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

[typescript]: calling `document.body.classList.contains` without checking for NULL object

Open quadruple-output opened this issue 7 months ago • 3 comments

Bug Description

In packages/base/src/util/getEffectiveScrollbarStyle.ts, there is a call to function document.body.classList.contains() without a prior check whether classList is not NULL. This breaks (at least in Safari on MacOS) when the <body> element has no class.

This may be trivial for most consumers to work around, but I happen to use a web framework that does not easily let me specify the class attribute for the <body> element.

Affected Component

package base

Expected Behaviour

There should be a check whether classList is not NULL, before calling contains() on it.

Isolated Example

No response

Steps to Reproduce

I do not think that this needs steps for reproduction, but I would elaborate more, if you need further information.

Log Output, Stack Trace or Screenshots

Image

Priority

Medium

UI5 Web Components Version

2.10.0

Browser

Safari

Operating System

MacOS

Additional Context

No response

Organization

No response

Declaration

  • [x] I’m not disclosing any internal or sensitive information.

quadruple-output avatar May 25 '25 12:05 quadruple-output

Hi @quadruple-output,

We're working with document.body in several places, and it's expected to return the <body> element. The body element inherits from the Element interface, which includes the classList property. According to TypeScript definitions, this property is read-only but should be present on the body element.

Could you please share more context about the framework you're using? This would help us investigate further and determine whether any adjustments are needed elsewhere before adding conditional logic.

Best regards, Nayden

nnaydenow avatar May 27 '25 10:05 nnaydenow

Silly me! While trying to provide a minimal example, I realized that the issue only occurs because I loaded the UI5 javascript from the <html><head> section, before the <body> tag was rendered.

You may close this issue. But perhaps, you could consider implementing a check that detects this situation, and issues a dedicated error, such that dummies like me don't waste much time investigating the root cause.

Have a nice day!

quadruple-output avatar Jun 06 '25 11:06 quadruple-output

Hello, everyone! The issue has been inactive for 21 days. If there are still questions or comments, please feel free to continue the discussion. Inactive issues will be closed after 7 days!

github-actions[bot] avatar Jun 28 '25 00:06 github-actions[bot]

This issue has been closed. To reopen, just leave a comment!

github-actions[bot] avatar Jul 04 '25 06:07 github-actions[bot]