Mikalai created SLING-13324:
-------------------------------

             Summary: Relative JS Use dependencies are not resolved via 
sling:resourceSuperType when the component is overlaid under a higher-priority 
search path (e.g. /apps over /libs)
                 Key: SLING-13324
                 URL: https://issues.apache.org/jira/browse/SLING-13324
             Project: Sling
          Issue Type: Bug
          Components: Scripting
    Affects Versions: Scripting HTL JS Use Provider 1.2.14
            Reporter: Mikalai


h2. Description

HTL scripts can load JavaScript Use-API scripts with a relative name, for 
example:
<sly data-sly-use.head="head.js"/>
Documented behavior: the engine should resolve {{head.js}} next to the caller, 
then walk the {{sling:resourceSuperType}} chain (same idea as overlaying only 
the Use script without overlaying the HTL caller).

In {{org.apache.sling.scripting.sightly.js.provider}} 1.2.x, resolution is 
anchored on the request resource type through the search path. If the component 
exists under {{/apps}} and {{{}/libs{}}}, {{/apps}} wins. If that {{/apps}} 
node has no {{head.js}} and does not itself expose a usable super-type chain 
for the walk, resolution stops and throws:
Unable to load script dependency head.js.
This worked in 1.0.28, which resolved from the caller script (typically under 
{{{}/libs{}}}) and climbed inheritance from there.
h2. How to reproduce (no product-specific knowledge)

Use any Sling instance with search path {{{}/apps{}}}, {{/libs}} and the HTL JS 
Use provider 1.2.x.
h3. 1. Create this repository structure
/libs/demo/components/page
sling:resourceSuperType = "demo/components/base"
page.html
# intentionally NO head.js here
 
/libs/demo/components/base
head.js
 
/apps/demo/components/page
# overlay: same relative type as /libs
# optional: only add an unrelated script, e.g. body.js
# do NOT add head.js
# do NOT set sling:resourceSuperType (common overlay mistake / partial overlay)
body.js
Minimal {{page.html}} (under {{{}/libs/.../page{}}}):
<!DOCTYPE html>
<html>
<body>
<slydata-sly-use.head="head.js"></sly>
<p>${head.title}</p>
</body>
</html>
Minimal {{head.js}} (under {{{}/libs/.../base{}}}):
use(function () {
return\{title:"from base"};
});
h3. 2. Create content that uses the overlaid type
/content/demo/page
sling:resourceType = "demo/components/page"
h3. 3. Request the page

Open {{/content/demo/page.html}} (or the equivalent render URL).
h3. Actual

HTTP 500 (or script error):
Unable to load script dependency head.js.
h3. Expected

HTTP 200. Relative {{head.js}} resolves through inheritance to 
{{{}/libs/demo/components/base/head.js{}}}, same as when 
{{/apps/demo/components/page}} does not exist.
h3. Control (proves overlay is the trigger)

Delete {{/apps/demo/components/page}} and reload: page renders successfully 
with the same {{/libs}} scripts.
h2. Why it breaks
 # Caller HTL runs from {{{}/libs/demo/components/page/page.html{}}}.
 # Driver/resource type resolves to {{/apps/demo/components/page}} (search 
path).
 # Resolver starts the hierarchy walk at {{{}/apps{}}}.
 # {{/apps}} has no {{head.js}} and often no {{{}sling:resourceSuperType{}}}.
 # Fallback only checked the caller folder ({{{}getChild{}}}), and did not 
climb the caller’s super-type chain → miss on 
{{{}/libs/demo/components/base/head.js{}}}.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to