Repository navigation
fix(blocks): layout sections are never deferred, even when marked ⚡ - #573
Closed
aline-pereira wants to merge 1 commit into
Closed
aline-pereira wants to merge 1 commit into
aline-pereira wants to merge 1 commit into
Conversation
`shouldDeferSection` already has the guard — it is just below the admin ⚡
check, so it never runs for the case it was written for:
// ~1656
if (cfg.respectCmsLazy && isCmsDeferralWrapped(section, matcherCtx)) return true;
…
// ~1667 — unreachable for any ⚡ layout section
// "deferring them would flash a skeleton on every navigation"
if (isLayoutSection(finalKey)) return false;
A named `Footer` block whose root is `Lazy.tsx` is ordinary in decofiles
carried over from Deco on Fresh — the editor never chose it, the migration did.
With the guard below the ⚡, that footer defers: it re-enters its skeleton on
every SPA navigation and only comes back once the user scrolls it into view.
Measured on a production storefront: skeleton on arrival at every route, ~530ms
to resolve after scrolling to the bottom.
It also crashes on the way there. The framework does not serialize `rawProps`
to the client, so a LoadingFallback is called with `{}` — and a footer fallback
that renders the real component (a documented convention; the same storefront's
Footer.tsx and ETCImageContent.tsx both do it) then hits
`<Newsletter {...undefined} />` and dies on `messages.success`, taking the
whole footer subtree down with it.
The site's only recourse was `setAsyncRenderingConfig({ respectCmsLazy: false })`,
which forces every ⚡ CONTENT section to render eagerly too. On that storefront's
home that meant 534 KB of HTML against the 160 KB its previous stack served, and
two JSON-LD `ItemList` blocks that the old site never published.
This moves `isLayoutSection` above the ⚡ check. It is now the only thing besides
the bot short-circuit that outranks the admin, and deliberately so:
`neverDefer`/`alwaysEager` stay below, where #277 put them. Those express a
section author's opinion about a CONTENT section and must not beat an editor's
explicit ⚡. "Should the site chrome disappear between pages" is a different
question — not one the ⚡ toggle is meant to answer, and the admin has no
separate control to say otherwise.
`export const deferred = true` still wins for a layout section: it sits above
this check, and a site that writes it means it.
Gate Evidence
blocks test ✅ 811 passed / 26 failed — as baseline (main: 807 / 26,
mesmas falhas pré-existentes em loader.test.ts); +4 testes
novos
blocks typecheck ✅ limpo
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
aline-pereira
added a commit
that referenced
this pull request
Sep 29, 2026
`isCmsDeferralWrapped` treats every `website/sections/Rendering/Lazy.tsx`
wrapper as a deferral, whatever props it carries. Fresh does not: the
wrapper's own loader short-circuits on `loading: "eager"` and renders the
inner section inline, with no FallbackWrapper.
```ts
// website/sections/Rendering/Lazy.tsx
const shouldRender = loading === "eager" || shouldForceRender({ … });
if (shouldRender) return { loading: "eager", section: await section() };
```
```tsx
if (loading === "lazy") {
return <ctx.FallbackWrapper …><section.Component … /></ctx.FallbackWrapper>;
}
return <section.Component {...section.props} />; // eager → inline
```
Decofiles carried over from Deco on Fresh use exactly that shape for the
named `Footer` block — `Lazy.tsx` at the root plus `loading: "eager"` — so
ignoring the prop turns a section prod server-renders into a skeleton that
only materializes client-side.
Measured on a migrated storefront (`/sobre`, `respectCmsLazy: true`), with
JavaScript disabled — i.e. what a non-rendering consumer of the HTML sees:
| | prod (Fresh) | migrated target |
|------------------------|--------------|-----------------|
| `<footer>` links | 17 | 2 |
| `<footer>` text length | 474 | 0 |
| links in the document | 27 | 11 |
Gone from the served HTML: the newsletter heading, the three social links,
all fourteen sitemap links, the postal address and the CNPJ. With JavaScript
on, the footer stayed empty at `scrollY = 0` for as long as it was observed
(16s) — it only filled once scrolled into view. Bots are unaffected:
`shouldDeferSection` already short-circuits on `isBotReq`.
The fix keeps walking inward after an eager wrapper instead of returning
`false` outright, so a nested lazy wrapper further down still defers —
mirroring Fresh, which resolves the inner section and lets its own loader
decide.
This is not a code-level override of the admin: `loading` is authored in the
CMS, so the editor stays the source of truth. It reads the whole instruction
instead of half of it, which is why it does not run into the objection that
closed #573.
Refs #573, #580, deco-sites/oficina-tanstack#419
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🎉 This PR is included in version 7.77.2 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The guard already exists — it is just in the wrong place
shouldDeferSectionhas exactly the right check. It sits below the admin ⚡ check, so it never runs for the case it was written for:A named
Footerblock whose root isLazy.tsxis ordinary in decofiles carried over from Deco on Fresh — the editor never chose it, the migration did. With the guard below the ⚡, that footer defers.Measured on a production storefront
Turning
respectCmsLazyon, on a real migrated store:data-deferred="true", 2 links)The content sections deferring is correct and desirable — that is the whole point of ⚡, and it took that store's home from 534 KB to 221 KB of HTML. The footer doing it is the failure.
It also crashes on the way there
The framework does not serialize
rawPropsto the client, so aLoadingFallbackis called with{}:A footer fallback that renders the real component — a convention this repo's own comment at
DecoPageRenderer.tsx:438documents ("see Footer.tsx/ETCImageContent.tsx in a production storefront migration's T64") — then hits<Newsletter {...undefined} />and dies:taking the whole footer subtree down with it.
What the site had to do instead
setAsyncRenderingConfig({ respectCmsLazy: false })— which forces every ⚡ content section to render eagerly too. On that storefront's home: 534 KB of HTML against the 160 KB its previous stack served, plus two JSON-LDItemListblocks the old site never published.The change
Moves
isLayoutSectionabove the ⚡ check. It becomes the only thing besides the bot short-circuit that outranks the admin, and deliberately so:neverDefer/alwaysEagerstay below, where Client-side navigation renders blank for deferred sections that depend on per-request app context (admin-source-of-truth deferral leaks into SPA nav) #277 put them. Those express a section author's opinion about a content section and must not beat an editor's explicit ⚡. That reasoning is untouched.export const deferred = truestill wins for a layout section — it sits above this check, and a site that writes it means it.Tests
isLayoutSectionwas mocked to a constantfalse, so no test could reach the guard. The mock is now a controllable key set (default still false — every existing test is unaffected), plus 4 cases:foldThreshold)export const deferred = truestill wins for a layout sectionGate Evidence
blocks testmain; as mesmas 26 falhas pré-existentes emloader.test.ts, +4 testes novosblocks typecheckRelacionado: deco-sites/oficina-tanstack#396 (a PR do site que liga
respectCmsLazye depende desta), #569.🤖 Generated with Claude Code
Summary by cubic
Fixes layout sections (Header, Footer, Theme) deferring when marked ⚡, which caused chrome skeletons to flash on every SPA navigation and could crash the footer subtree when
LoadingFallbackreceived empty props.Bug Fixes
export const deferred = truewinning and leavesneverDefer/alwaysEagerordering untouched.rawPropsserialization and the 530ms skeleton‑and‑scroll delay measured on a migrated storefront.Written for commit 14bfd65. Summary will update on new commits.