Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabled "manifestFirst" doesn't load resources defined in sap.ui5 #1398

Closed
boghyon opened this issue Mar 27, 2017 · 8 comments
Closed

Enabled "manifestFirst" doesn't load resources defined in sap.ui5 #1398

boghyon opened this issue Mar 27, 2017 · 8 comments

Comments

@boghyon
Copy link
Contributor

boghyon commented Mar 27, 2017

OpenUI5 version: All

URL (minimal example if possible): https://embed.plnkr.co/4mURwe/
(Update 2017.04.22: Added mandatory attributes in the app descriptor)

Steps to reproduce the problem:

  1. Define any CSS or JS resources in the sap.ui5 namespace of app descriptor
  2. Enable manifestFirst either in the bootstrap configuration or in the component factory
  3. If available, remove manifest: "json" from the component metadata in order to avoid loading the file twice.

What is the expected result?
CSS and JS files are loaded and applied.

What happens instead?
Requests for those files aren't even sent.

Any other information? (attach screenshot if possible)
I couldn't find any mention about this behavior in the documentation. The CSS and JS resources gets loaded when manifest: "json" is defined in the component metadata. But this will send another request to manifest.json even if the descriptor was loaded already through manifestFirst.

@Shtilianova
Copy link
Contributor

I've created a internal incident 1770165096. You can check its status on GitHub.

@matz3
Copy link
Member

matz3 commented Apr 21, 2017

Your manifest.json is not valid.
The mandatory sap.app/id is missing, see:
https://openui5.hana.ondemand.com/#docs/guide/be0cf40f61184b358b5faedaec98b2da.html

This is why the file is loaded twice when using manifestFirst as the manifest can't be mapped to the corresponding component. If manifest: "json" is not provided it can still not use it as the Component needs to declare that it is using a manifest.

@boghyon
Copy link
Contributor Author

boghyon commented Apr 21, 2017

@matz3 Ahh, I see. Thanks for pointing this out! I didn't see the connection between sap.app/id and the component name. Anyhow, I should have added the id anyway since it's marked as mandatory.

@boghyon boghyon closed this as completed Apr 21, 2017
@boghyon
Copy link
Contributor Author

boghyon commented Apr 22, 2017

@matz3 Sorry, I overlooked that even after adding all the mandatory attributes (such as sap.app/id with the corresponding component name) and enabling component metadata, I'm still getting the same manifest.json file twice. This can be also seen in this ComponentManifestFirst test after reloading the page and pressing the "Load Component" button:
image
The ComponentMetadata doesn't seem to check whether manifest.json has been already loaded before or not. As I understood, I shouldn't remove manifest: "json" to avoid this behavior. Did I misconfigure or misunderstand something?

@boghyon boghyon reopened this Apr 22, 2017
@matz3
Copy link
Member

matz3 commented Apr 27, 2017

@boghyon you are right. The file is loaded twice in this case.

The first request is triggered via the manifestFirst option which will load the manifest for the instance that is about to be created. This manifest object is also assigned to that instance allowing to load a different manifest (e.g. with different configuration) via the manifestUrl option (manifestFirst does the same as manifestUrl, just with the default URL).

The second request is triggered via sap.ui.core.ComponentMetadata which is statically created for the component class. This is mainly required for compatibility reasons with other use cases. In your case it won't be used by the component instance at all, as it has it's own manifest object already.

The reason why there are two requests is because this scenario has been optimized for the productive use where the Component-preload.js (404 in your case) also contains the manifest.json file. This way the additional request would be prevented, resulting into two requests:

  1. manifest.json
  2. Component-preload.js (contains Component.js, manifest.json, ...)

To create the Component-preload.js file you can use the openui5_preload Grunt task:
https://github.com/SAP/grunt-openui5#openui5_preload

Here is a sample app using that task:
https://github.com/SAP/openui5-sample-app

@matz3 matz3 closed this as completed Apr 27, 2017
@boghyon
Copy link
Contributor Author

boghyon commented Apr 28, 2017

@matz3 I see. Thanks for the clarification. It would be nice if the behavior you described is in the doc somewhere where manifestFirst is mentioned. I think there were and will be more devs wondering why the request to the same file is sent twice (in case no Component-preload.js is available) which might even lead them to remove the manifest assignment in the component metadata (like I did before :P).

@boghyon
Copy link
Contributor Author

boghyon commented May 29, 2018

Just to note down for other readers what I observed: Since 1.54.0 (and without Component-preload.js), the manifest file is not loaded twice anymore but only when there was a name provided in the component creation. E.g.:

sap.ui.component({
  name: "...",
  manifest: true
})

If a URL is given instead (manifest: "myPath.json"), the manifest file is loaded twice again.

@matz3
Copy link
Member

matz3 commented Jun 1, 2018

@boghyon that's right. We've optimized the manifest loading internally to share it with the ComponentMetadata class.
Sorry for not updating this issue. This was done with 0e271c9.

If a URL is given instead (manifest: "myPath.json"), the manifest file is loaded twice again.

Yes, this is my design as the manifest loaded from a different location could have a different content than the one loaded from the default location. So we only share it in case the resulting URL would be the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants