Openui5: sap.ui.core.Fragment.load is not async

Created on 22 Mar 2019  路  5Comments  路  Source: SAP/openui5

OpenUI5 version: <= 1.65.0

URL (minimal example if possible): https://embed.plnkr.co/IcOrLE/

Steps to reproduce the problem:

  1. Run the Plnkr example;
  2. Open Browser Dev Tools;
  3. Check network requests.

What is the expected result?
sap.ui.core.Fragment.load returns a Promise, it should load the fragments async.

What happens instead?
sap.ui.core.Fragment.load returns a Promise, however it load the fragments sync.

Any other information? (attach screenshot if possible)
Fragment load_sync
_Fragment.load sync_

Fragment load_sync_01
_Fragment.load sync requests_

Fragment load_async
_Fragment.load async (proposal)_

Fragment load_async_01
_Fragment.load async requests (proposal)_

enhancement in progress

Most helpful comment

Quick update on this topic, since we had a couple of inquires in the last days and weeks:
We have just started working on this.

As @codeworrior mentioned, we aim for more than just the asynchronous behavior of the factory.
We also want to integrate the asynchronous loading of fragments into the regular XML processing workflow.
So fragments inside XMLViews, as well as nested Fragments are in our current scope.

We will update the Github issue once we got a commit done.

All 5 comments

Thank you for the detail report. This is known and on our backlog.

I was going to create a pull request, it seems it's not necessary... Here is my fix, just in case...

In Fragment.load, I've replaced return Promise.resolve(fragmentFactory(mParameters)) by return Promise.resolve(fragmentFactoryAsync(mParameters)).

Also, I've created these functions to load it async:

function fragmentFactoryAsync(vName, vType, oController) {
      var mSettings = {};
      if (typeof (vName) === "string") { // normal call
        mSettings.fragmentName = vName;
        mSettings.oController = oController;
        mSettings.type = vType;

      } else if (typeof (vName) === "object") { // advanced call with config object
        mSettings = vName; // pass all config parameters to the implementation
        if (vType) { // second parameter "vType" is in this case the optional Controller
          mSettings.oController = vType;
        }
      } else {
        Log.error("sap.ui.fragment() must be called with Fragment name or config object as first parameter, but is: " + vName);
      }
      if (vType === "XML") {
        return loadFragmentXMLAsync(mSettings);
      } else {
        return new Fragment(mSettings);
      }
    }

    function loadFragmentXMLAsync(mSettings) {
      return XMLTemplateProcessor.loadTemplatePromise(mSettings.fragmentName, "fragment")
        .then(function(documentElement) {
          mSettings.fragmentContent = documentElement;
          return new Fragment(mSettings);
        });
    }

To be honest, I don't remember exactly what kept us from implementing this together with the async factory method. In the past, we had some compatibility issues with internal apps that stumbled upon async view loading, e.g. in their integration tests. As we propagate the async flag from views to nested fragments, this might have been one issue.

In other words: I expect delays in reviewing a PR due to the compatibility questions. If you don't mind that, a PR would be appreciated.

[Update] I should mention that our backlog task not only targets the async loading of the fragment XML but also the async processing of its content (e.g. requiring controls and further fragments async). That's the tricky part reg. compatibility.

Quick update on this topic, since we had a couple of inquires in the last days and weeks:
We have just started working on this.

As @codeworrior mentioned, we aim for more than just the asynchronous behavior of the factory.
We also want to integrate the asynchronous loading of fragments into the regular XML processing workflow.
So fragments inside XMLViews, as well as nested Fragments are in our current scope.

We will update the Github issue once we got a commit done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

git-ashish picture git-ashish  路  4Comments

MagicCube picture MagicCube  路  4Comments

whydrae picture whydrae  路  4Comments

seiupo picture seiupo  路  3Comments

TinaC picture TinaC  路  4Comments