I think I've found two issues with the lntg:require tag, especially with the styles attribute (when previewing as a guest).

First, some context:

Let's say I have a CSS file as a static resource named Foo. Its content is not relevant, but for test purpose, let's say it's just this snippet:

div {
    color: red;

I want to import it in my Lightning component, to do so, I use this code:

<aura:component implements="forceCommunity:availableForAllPageTypes" access="global" >
    <ltng:require styles="{!$Resource.Foo}"></ltng:require>
    <div>My div are awesome!</div>

Then, I create a brand new Community and put my component in the builder. All good in the builder, when I'm previewing (either directly in the builder or as an authenticated user) or even on the published site (either as a guest or an authenticated user).

However, when I try to preview as a guest, things start to glitch out.

The first issue I encountered, the CSS file is not accessible due to CSP restrictions: Refused to load the stylesheet 'https://na85.salesforce.com/commbuilder/session?url=https%3A%2F%2Ffoobarbazbar-developer-edition--preview.na85.force.com%2Fresource%2F1550521739000%2Foo' because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline' http://c.na85.content.force.com foobarbazbar-developer-edition.na85.force.com". Note that 'style-src-elem' was not explicitly set, so 'style-src' is used as a fallback.

To mitigate that one I add https://na85.salesforce.com/ in the CSP trusted site (which itself is really odd). Another issue then occur: Refused to apply style from 'https://foobarbazbar-developer-edition--preview.na85.force.com/resource/1550523152000/barfoo' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

This is kinda odd, the MIME type of the resource is detected as text/css when checking the static resource itself, so it seems to me that the ltng:require or the preview as guest feature have some kind of incompatibility/issues right now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.