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.92k stars 1.23k forks source link

`_enforceNoReturnValue.js` does not allow for async lifecycle hooks #4014

Closed dfenerski closed 2 months ago

dfenerski commented 3 months ago

OpenUI5 version: latest, 1.120 LTS

URL (minimal example if possible):

https://github.com/dfenerski/ui5-async-controller-lifecycle-issue

Steps to reproduce the problem:

The addition of the _enforceNoReturnValue module here 6f52e5142b2c18b2e3f38b4b053e43a9b957edb3 now logs a "future fatal" whenever a lifecycle hook with return value different than undefined is detected. But async functions always return a Promise. Therefore this change disables the possibility to use async lifecycle hooks.

What is the expected result? Async lifecycle hooks are OK

What happens instead?

Log.js?eval:499 2024-03-25 14:30:08.586099 [FUTURE FATAL] The registered Event Listener 'onInit' must not have a return value. - com.github.dfenerski.issue_async_controller_lifecycle.controller.Main 

Screenshot: image

devtomtom commented 3 months ago

Hi @dfenerski,

We recently allowed developers to use the async/await syntax for listeners to control events. However, it is important to note that using async functions within the lifecycle hooks of the framework is still restricted. With this module _enforceNoReturnValue the framework reserves the introduction of a return type in the future. As you pointed out correctly, using async functions would already result in a return value that might conflict with such a later change.

Please see the updated ECMAScript Support page.

Also please have a look at the updated API Reference: sap.ui.core.mvc.Controller#onInit.

Best regards, Tommy

dfenerski commented 3 months ago

Thanks for the info! I missed the docs - sorry for that

dfenerski commented 3 months ago

@devtomtom it seems sap.ui.core.mvc.ControllerExtensions are also affected, if they define async onLifecycleEvent in their override section. Should they be mentioned in the support & API reference pages too?

devtomtom commented 3 months ago

@devtomtom it seems sap.ui.core.mvc.ControllerExtensions are also affected, if they define async onLifecycleEvent in their override section. Should they be mentioned in the support & API reference pages too?

@dfenerski Good point, thanks! Yes, it definitely should be mentioned there too.

thisisevanfox commented 2 months ago

Hi all,

I came across this problem by chance because we are getting a similar error in our Build Workzone, standard edition Launchpad and maybe it is related.

We integrate various specially developed cloud apps and on-premise apps into the WorkZone. We are using view mode "Spaces and Pages - New Experience". For a few days now, various errors have been occurring again and again, making it almost impossible to use the Launchpad.

  1. Error - Tiles cannot be loaded 3-CanNotLoadTile

  2. Error - CSS is not loaded 1-NoCss

  3. Error - Strange bar appears 2-Bar

The Launchpad uses SAPUI5 version 1.123.1 (built at 2024-04-18T13:07).

Maybe the problem is really related and my input is somehow helpful.

I also raised an issue on me.sap.com: 377725/2024.

Kind regards, Johannes

devtomtom commented 2 months ago

Hi @thisisevanfox, the error messages concerning the return value of the hooks shouldn't affect your application. The same is true for the other [FUTURE FATAL] messages... There must be other reasons for the errors described. Can you provide me the URL to the issue you reported

thisisevanfox commented 2 months ago

Hi @devtomtom,

see here:

I also raised an issue on me.sap.com: 377725/2024.

Kind regards, Johannes

flovogt commented 2 months ago

Closing this issue here. Further updates will be done in the SAP support incident.