SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.94k stars 1.23k forks source link

Assertion failed: Method 'class' must be called with exactly one class name... Why? #3981

Closed ybbus closed 6 months ago

ybbus commented 6 months ago

OpenUI5 version: 1.120.6

Steps to reproduce the problem:

  1. Create a custom Component
  2. const rm: RenderManager
  3. rm.class("flex flex-row text-slate-500")

What is the expected result? Works without complaint.

What happens instead? Assertion failed: Method 'class' must be called with exactly one class name

Any other information?

Why is there an assertion for that? It works anyway as expected even so assertion fails. We are working heavily with tailwind on custom components and beeing able to only provide one class per ´´´class()´´´ call would be a nightmare. :)

codeworrior commented 6 months ago

This restrictions has been added to allow the Patcher to potentially handle class() calls differently in future, e.g. to map them directly classList manipulations (without the need to parse the given argument).

If you ignore the assertion, your code might fail in future versions of UI5.

But there's an alternative: the RenderManager meanwhile allows to use the attr() method also for class and style attributes. You just must not mix the two approaches for a single element. If you use attr("class", someClassList), you must not use class(someClass) for the same element, same for attr("style", someStyles) and style(someStyle, someStyleValue).