[typescript]: calling `document.body.classList.contains` without checking for NULL object
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
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.
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
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!
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!
This issue has been closed. To reopen, just leave a comment!