adobe / adobe/aem-core-wcm-components
[Container] Not working with TemplatedResource / Wrapped / Synthetic resources
- Dominant language
- Java
- Stars
- 795
- Forks
- 775
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 8
Description
## Bug Report
**Current Behavior**
If a resource, rendered as a Container Component, has children which are not JCR-backed resources (i.e. a TemplatedResource, a wrapped resource, or other type of synthetic resource, this information is lost when rendering the child due to relying on the "path" for rendering the child.
**Expected behavior/code**
The child resource should be rendered directly,
we already have the resource, there is no need to use the path to re-resolve the resource.
**Environment**
- AEM 6.5.4.0
- Core Components version 2.8.0
**Possible Solution**
The issue is introduced [here](https://github.com/adobe/aem-core-wcm-components/blob/c69fdc63fc0f2fb122d65eb4091d9bef872e09fb/content/src/content/jcr_root/apps/core/wcm/components/form/container/v2/container/container.html#L25)
``
Specifically, the use of `${paragraph.path}`.
The actual resource that we want to render is already available at `${paragraph.resource}`.
By using the path we force the resource resolver to fetch the resource anew from the specified path.
This isn't a huge issue for any standard non-wrapped JCR-backed resource, or any resource for which a ResourceProvider is registered to be able to resolve the resource such that `ResourceResolver.get(resource.getPath()) === resource`.
However, if the child resource has been wrapped and modified (as is the case with com.day.cq.wcm.api.TemplatedResource) then any of that information is lost during the re-resolution of the resource based on it's path. In this situation `ResourceResolver.get(resource.getPath()) !== resource`,
In fact, `com.day.cq.wcm.foundation.model.responsivegrid.ResponsiveGrid#getParagraphs()` (used in the Container Component) returns resources that are wrapped as a TemplatedResource, and then again as a ResponsiveColumn resource.
We can avoid having to re-resolve the the resources and not lose any of the wrappers If the quoted lines are changed to this:
``
**Additional context / Screenshots**
As a side note; the same bug exists in the OOTB responsivegrid component. (to anyone working at Adobe: feel free to fix this there :D )
My general rule is that if the resource you want to render is available to you as a Resource object, just use the resource directly in your data-sly-resource call, it only causes problems to go resource -> path -> resource.
I believe that a String (path) should only be used if it is:
1) the path is static; or,
1) the path is relative to the current resource; or,
2) the model does not provide the resource, only the paths.
Contributor guide
Research direction
Start by inspecting content/src/content/jcr_root/apps/core/wcm/components/form/container/v2/container/container.html at the data-sly-resource call identified in the issue. Verify that the child is rendered from the provided resource rather than re-resolved from its path, and confirm that TemplatedResource, wrapped, and synthetic child information is preserved.
Written by the indexing model from the issue text.
Assessment
- Domain
- web-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 30/100