Open boghyon opened 5 years ago
For future UI5 control development based on UI5 Web Components, follow https://github.com/SAP/ui5-webcomponents/issues/2926
Hello @boghyon , Thank you for sharing this awesome summary. Sorry, that we've not responded to your input so long. I've created an internal incident 2280031660. The status of the issue will be updated here in GitHub.
@boghyon & @flovogt: I consolidated this issue and the one about function usage in an internal backlog item: CPOUI5FRAMEWORK-343 See also my other comment on https://github.com/SAP/openui5-docs/issues/33
Controls should not rely on
rerender
being called anyway since https://github.com/SAP/openui5/commit/378b5982b6c309d269d52b3807485c1f10762d81.
SNOW: CS20240007695164
It would be nice if there is a central place to learn about how renderings are done in UI5 (Especially for new developers with experience in popular frameworks).
1. General understanding
For newcomers and researchers:
Linking to other resources like Extended Change Detection,
InvisibleRenderer.render
, etc…2. Implementing renderers
For advanced UI5 developers:
ResizeHandler
or other event registration inonAfterRendering
. Simply replacing the legacy (now-deprecated) APIs with the new ones might be insufficient since the existing element in DOM will be reused withapiVersion
2 or higher. Sample commit: https://github.com/SAP/openui5/commit/6525fed3d98391146d4c52630429f24f5c2c8fddHTMLElement
s, such as SVGs? (SO question #75424952)Related talk by @akudev: Embedding 3rd-party widget as UI5 control [video]
@abstract
controls should haverenderer: null
assigned. Otherwise,MyControlRenderer.js
can be accidentally fetched in some cases, leading to a 404 error. Abstract controls don't have renderers by definition.Sample commit: https://github.com/SAP/openui5/commit/50da9eedc2bf4a024694f2f84dd4c7c13cb2200c
ManagedObject.escapeSettingsValue
in the constructor settings object (since v1.52) or the mutator (e.g.setText
) after the control instantiation should be used.Sample issues and fixes: https://github.com/SAP/openui5/issues?q=is%3Aissue+curly+escapeSettingsValue
RenderManager#icon
, the renderer module for the control should requiresap/ui/core/IconPool
in order to avoid synchronous loading of the dependency.Sample commit: https://github.com/SAP/openui5/commit/7dddccdedfff78a47e39a3a8bf21cb224b7fa761
openStart
and provide an ID as a 2nd argument (control.getId() + "-myInnerEl"
) instead of usingattr("id", "...")
so that the Patcher can reuse the existing DOM elements again when rerendering.Sample commit: https://github.com/SAP/openui5/commit/3756b0edcfb0d0e56f03f8a6d7bb287069c67036
rerender
norinvalidate
is designed to be overwritten by controls, that intend to further manipulate the DOM there, which should be avoided in favor ofonAfterRendering
. Controls should not rely onrerender
being called anyway since https://github.com/SAP/openui5/commit/378b5982b6c309d269d52b3807485c1f10762d81.Motivation
Currently, it's easy for new developers to get lost when trying to understand the above mentioned points. When going through the documentation:
write*()
,add*()
, …)Some use the new semantic rendering APIs (
openStart()
,class()
,attr()
, …) For beginners, it's not clear which one is new and which one is old.renderer
assignments:renderer: { render: <fn> }
(should include at leastapiVersion: 2
or higher to enable the DOM-patching)renderer: <fn>
(should be avoided: https://github.com/SAP/openui5-docs/issues/33)renderer: "sap.m.SomeRenderer"
renderer: MyRequiredRenderer
(Current best-practice AFAIK. Cf. https://github.com/SAP/openui5/commit/ad5bc4efdd2b7d29cfb88ffe37554c8074eaec98 and https://github.com/SAP/openui5/commit/f0fa93fdfe6d1c5104598e191235c4371c603cb3)Code snippets with inconsistent renderer definitions:
In the control definition itself at
renderer
A separate renderer module (e.g.
MyControlRenderer.js
)Returning a plain object with
bExport
true
(Not intended to be used for non-SAP developers)Returning
Renderer.extend(/*…*/);
whereasRenderer
is required fromsap/ui/core/Renderer
(Current best-practice AFAIK)[ ] One or two topics that explain all the above points would help people to grasp rendering in UI5 quickly. Additionally, the Best Practices for Developers section "Control rendering" should be also enhanced afterwards.