Skip to content
Closed
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
2 changes: 2 additions & 0 deletions website/manifest.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import * as $$$$$$$14 from "./matchers/site.ts";
import * as $$$$$$$15 from "./matchers/userAgent.ts";
import * as $$$$$0 from "./pages/Page.tsx";
import * as $$$$$$0 from "./sections/Analytics/Analytics.tsx";
import * as $$$$$$6 from "./sections/Cache/AllowPageCache.tsx";
import * as $$$$$$1 from "./sections/Rendering/Deferred.tsx";
import * as $$$$$$2 from "./sections/Rendering/Lazy.tsx";
import * as $$$$$$3 from "./sections/Rendering/SingleDeferred.tsx";
Expand Down Expand Up @@ -89,6 +90,7 @@ const manifest = {
},
"sections": {
"website/sections/Analytics/Analytics.tsx": $$$$$$0,
"website/sections/Cache/AllowPageCache.tsx": $$$$$$6,
"website/sections/Rendering/Deferred.tsx": $$$$$$1,
"website/sections/Rendering/Lazy.tsx": $$$$$$2,
"website/sections/Rendering/SingleDeferred.tsx": $$$$$$3,
Expand Down
25 changes: 25 additions & 0 deletions website/sections/Cache/AllowPageCache.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { PAGE_CACHE_ALLOWED_KEY } from "@deco/deco/blocks";
import type { AppContext } from "../../mod.ts";

/**
* Opts the current page into CDN page caching.
*
* The runtime only emits a public `Cache-Control` when some middleware marks
* the request as safe to cache (see `PAGE_CACHE_ALLOWED_KEY`). Commerce apps
* like VTEX do this from their middleware, but CMS-only pages (e.g. a home
* built purely from `website` sections, with no commerce loader) never opt in
* and therefore stay uncached.
*
* Drop this section on such a page to make it cacheable. It is still guarded by
* the runtime: if a foreign `Set-Cookie` is present, or another block on the
* same page marks the response `no-store`, that decision wins.
*/
export const loader = (_props: unknown, _req: Request, ctx: AppContext) => {
ctx.bag?.set(PAGE_CACHE_ALLOWED_KEY, true);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The loader uses ctx.bag?.set(...), which will silently do nothing if bag is undefined — but setting this key is the sole purpose of the section, so a silent no-op means the page stays uncached with no indication why. The VTEX middleware this PR mirrors uses non-optional ctx.bag.set(...); consider matching that or adding a warning if bag is missing.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At website/sections/Cache/AllowPageCache.tsx, line 18:

<comment>The loader uses `ctx.bag?.set(...)`, which will silently do nothing if `bag` is undefined — but setting this key is the sole purpose of the section, so a silent no-op means the page stays uncached with no indication why. The VTEX middleware this PR mirrors uses non-optional `ctx.bag.set(...)`; consider matching that or adding a warning if bag is missing.</comment>

<file context>
@@ -0,0 +1,25 @@
+ * same page marks the response `no-store`, that decision wins.
+ */
+export const loader = (_props: unknown, _req: Request, ctx: AppContext) => {
+  ctx.bag?.set(PAGE_CACHE_ALLOWED_KEY, true);
+  return {};
+};
</file context>

return {};
};

// Renders nothing — this section exists only to opt the page into caching.
export default function AllowPageCache() {
return null;
}
Loading