Repository navigation
fix(blocks): honour loading: "eager" on a CMS Lazy wrapper - #583
Merged
Merged
Conversation
`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]>
aline-pereira
force-pushed
the
fix/lazy-loading-eager
branch
from
September 29, 2026 18:18
2527fa2 to
1f2cd31
Compare
guitavano
approved these changes
Oct 8, 2026
|
🎉 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 prop Fresh reads and we do not
isCmsDeferralWrappedreturnstruefor anywebsite/sections/Rendering/Lazy.tsxwrapper, whatever props it carries:Fresh's own
Lazy.tsxdoes not.loading: "eager"short-circuits its loader, which awaits the inner section and renders it inline — noFallbackWrapper, no second hop:Decofiles carried over from Deco on Fresh use exactly that shape for the named
Footerblock —Lazy.tsxat the root plusloading: "eager". The editor never chose it; the migration produced it. So a section prod server-renders becomes a skeleton that only materializes client-side.On the storefront that surfaced this, it is the only block with the prop: 8 blocks are
Lazy-wrapped, exactly 1 is eager.Measured end to end
bun run preview(production Cloudflare Workers build) of a migrated storefront,/sobre,respectCmsLazy: true, browser User-Agent, cache MISS. Same harness, same build, only this commit differs:data-deferredon the footer<footer>links in the served HTML<footer>text lengthMissing from the served HTML before the fix: 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 = 0for as long as it was observed (16s) — it only filled when scrolled into view.Instrumenting
shouldDeferSectionconfirms the predicate is what flips:wrappedwastruebefore this commit. With itfalse, the already-presentisLayoutSectionguard below finally gets to run — which is the check the file's own comment says exists for Header/Footer/Theme.Two traps worth flagging for anyone reproducing this:
curlis classified as a bot, andshouldDeferSectionshort-circuits onisBotReq, so it takes the eager path regardless and shows no difference. Use a browser UA.x-cache: HITfrom the pre-fix build. Bust the URL.vite devis not a usable harness: it emits no Suspense placeholders and nodata-deferred, and server-renders the footer even unpatched.Bots were never affected by the bug, which is why crawlers still saw the full footer.
The change
One branch in
isCmsDeferralWrapped. An eager wrapper keeps walking inward rather than returningfalseoutright, so a nested lazy wrapper further down still defers — mirroring Fresh, which resolves the inner section and lets its own loader decide.The eager render path needs nothing:
internalResolvealready unwrapsLAZYtoobj.section.Why this is not #573 again
#573 proposed moving the
isLayoutSectionguard above the admin ⚡ check, which fought the documented rule that the admin is the source of truth and no code flag may override it. This adds no code-level override:loadingis authored in the CMS. The editor stays the source of truth — we just read the whole instruction instead of half of it.Tests
Three added to
shouldDeferSection: an eager wrapper is not deferred;loading: "lazy"and a wrapper with noloadingstill defer; an eager wrapper around a lazy one still defers.resolve.test.tsgreen (82/82).tsc --noEmitonpackages/blocksclean.No existing test in the monorepo constructs a Lazy/Deferred wrapper with a
loadingprop (zerogrephits across every*.test.ts*before this PR), so the change is inert for the rest of the suite.packages/blockshas pre-existing failures onmainand the suite is flaky under load — three runs of near-identical code gave 41, 43 and 60 failures.layoutCacheRace.test.tswas checked directly and fails identically with and without this commit.Prettier already flags both touched files on
main, so they were left unformatted rather than reflowed into an unrelated diff.Refs #573, #580, deco-sites/oficina-tanstack#419, deco-sites/oficina-tanstack#430
🤖 Generated with Claude Code