Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .chachalog/Kp7mQx2R.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
javascript-modules: minor
---

`buildNodeUrl` now autocollects cache dependencies for the content it links to, preventing 404 errors when the linked content is renamed or moved. (#783)
`buildNodeUrl` now autocollects cache dependencies for the content it links to, preventing 404 errors when the linked content is renamed or moved. (#783, #810)
Comment thread
jkevan marked this conversation as resolved.

This mechanism is enabled by default but can be disabled on a per-view basis by setting `"cache.autocollectDependencies": "false"` in the view's properties, or on a per-call basis with the new `autocollectDependency: false` option in `buildNodeUrl`.

When a view links to more than 100 contents, a change in a folder that holds many of them also refreshes the view.
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
import { buildNodeUrl, jahiaComponent } from "@jahia/javascript-modules-library";
import { buildNodeUrl, jahiaComponent, Render } from "@jahia/javascript-modules-library";
import type { JCRNodeWrapper } from "org.jahia.services.content";

interface Props {
image: JCRNodeWrapper;
}

const ImageAndRenderMarker = ({ image, testId }: { image: JCRNodeWrapper; testId: string }) => (
const ImageAndRenderMarker = ({ src, testId }: { src: string; testId: string }) => (
<div data-testid={testId}>
<img src={buildNodeUrl(image)} alt="" />
<img src={src} alt="" />
<span data-testid={`${testId}_rendered_at`}>{String(Date.now())}</span>
</div>
);

/**
* Neither view declares a cache dependency: building the URL is what registers one. The two differ
* only in whether they let the engine collect it.
* No view declares a cache dependency: building the URL is what registers one. The views differ
* only in whether they let the engine collect it, and in how they call `buildNodeUrl`.
*/
jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
componentType: "view",
},
({ image }: Props) => <ImageAndRenderMarker image={image} testId="autocollected" />,
({ image }: Props) => <ImageAndRenderMarker src={buildNodeUrl(image)} testId="autocollected" />,
);

jahiaComponent(
Expand All @@ -31,5 +31,87 @@ jahiaComponent(
componentType: "view",
properties: { "cache.autocollectDependencies": "false" },
},
({ image }: Props) => <ImageAndRenderMarker image={image} testId="optedout" />,
({ image }: Props) => <ImageAndRenderMarker src={buildNodeUrl(image)} testId="optedout" />,
);

/** The context is passed explicitly, as a helper outside a component does. */
jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "explicitcontext",
componentType: "view",
},
({ image }: Props, { renderContext, currentResource }) => (
<ImageAndRenderMarker
src={buildNodeUrl(image, {}, { renderContext, currentResource })}
testId="explicitcontext"
/>
),
);

jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "callopout",
componentType: "view",
},
({ image }: Props) => (
<ImageAndRenderMarker
src={buildNodeUrl(image, { autocollectDependency: false })}
testId="callopout"
/>
),
);

/**
* The cache stores an include inside the fragment of its parent. The included view builds the URL,
* so the parent fragment must depend on the image.
*/
jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "includeparent",
componentType: "view",
},
() => <Render advanceRenderingConfig="INCLUDE" view="includedimage" />,
);

jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "includedimage",
componentType: "view",
},
({ image }: Props) => <ImageAndRenderMarker src={buildNodeUrl(image)} testId="included" />,
);

/**
* A virtual node renders inside the fragment of its parent, which the cache stores with it. The
* view of the virtual node builds the URL, so the parent fragment must depend on the image.
*/
jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "virtualparent",
componentType: "view",
},
({ image }: Props) => (
<Render
content={{
name: "autocollectedVirtualNode",
nodeType: "javascriptExample:testAutocollectedCacheDependency",
properties: { image: image.getIdentifier() },
}}
view="virtualimage"
/>
),
);

jahiaComponent(
{
nodeType: "javascriptExample:testAutocollectedCacheDependency",
name: "virtualimage",
componentType: "view",
},
({ image }: Props) => <ImageAndRenderMarker src={buildNodeUrl(image)} testId="virtual" />,
);
Loading
Loading