Styles missing for experience fragments in AEM author
I am using the front-end pipeline, thus not using clientlibs but having the css and js served from the CDN via links like:
<script src="http://127.0.0.1:4173/theme.js" type="module"></script>
<link href="http://127.0.0.1:4173/theme.css" type="text/css" as="style" rel="preload stylesheet">
This works on normal pages with experience fragments and it works in AEM author when authoring an experience fragment as well, via this code in the xfpage components customheaderlibs.html:
<sly data-sly-use.page="com.adobe.cq.wcm.core.components.models.Page"
data-sly-list="${page.htmlPageItems}">
<script data-sly-test="${item.location.name == 'header'}"
data-sly-element="${item.element.name @ context='unsafe'}"
data-sly-attribute="${item.attributes}"></script>
</sly>
However, I have now created a new Sling model for our custom page component like this:
@Model(
adaptables = SlingHttpServletRequest.class,
adapters = Page.class,
resourceType = "mycompany/components/corporate/page",
defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL
)
public class CorporatePageImpl implements Page {
@Self @Via(type = ResourceSuperType.class)
private Page delegate;
In this sling model, I do delegate the other Page methods as such:
@Override
public List<HtmlPageItem> getHtmlPageItems() {
return delegate.getHtmlPageItems();
}
But now the styles (those .css and .js links above) have vanished in AEM author when editing an experience fragment. What appears to be happening is that in customheaderlibs.html, the <sly data-sly-use.page="com.adobe.cq.wcm.core.components.models.Page" is returning my CorporatePageImpl Sling model, but then my delegated getHtmlPageItems method ends up throwing a NullPointerException. The delegate is not null, it is also an instance of CorporatePageImpl. I noticed on normal pages where this still works, it's an instance of PageImpl.
What is happening here and how can I get my styles when authoring experience fragments again?