Repository navigation
Description
Summary
The migrate script (scripts/migrate.ts) does not adapt deco.cx section loaders to @decocms/start's loader-invocation signature, so every migrated section loader that reads ctx throws at runtime and the page renders empty. This affects essentially every deco.cx storefront (all of them use section loaders with ctx), so fixing it in the migrate transform makes every future migration land correct instead of each site having to hand-fix dozens of loaders.
Root cause
deco.cx (Fresh) section loaders use a 3-arg signature:
export const loader = (props: Props, req: Request, ctx: AppContext) => {
const isMobile = ctx.device !== "desktop";
const page = await ctx.invoke.magento.loaders.product.detailsPageGQL({ ... });
const ext = ctx.salesforce?.cartExtension?.[0];
...
};But @decocms/start invokes section loaders with 2 args (src/cms/sectionLoaders.ts):
const enrichedProps = await loader(section.props, request); // lines ~129, ~282
return (props, req) => loader(injectPageContext(props, req), req); // line ~366injectPageContext only adds __pageUrl/__pagePath to props. There is no 3rd ctx arg, so ctx is undefined in every migrated loader → ctx.device / ctx.invoke / ctx.salesforce throw Cannot read properties of undefined. React bails SSR ("Switched to client rendering because the server rendering errored"), the section renders nothing, and a loader-heavy home ends up blank.
Observed on a real migration (/ served a shell with an empty <body>; dev.log):
5x section loader threw: Cannot read properties of undefined (reading 'salesforce')
4x Cannot read properties of undefined (reading 'href')
2x section loader threw: defaultLoader is not defined
1x reading 'invoke' / 'device' / 'customConfigs'
Related: SEO sections use deco.cx's defaultLoader / DefaultProps, which don't exist in start, so they also throw.
How a working migration solved it (proven pattern)
A hand-fixed migration (granadobr-tanstack) makes the loaders defensive:
// ctx is what setup/section-loaders composes (device, search params). Site-wide
// state (salesforce, features) is not always injected — keep every read optional.
export const loader = (props: Props, _req: Request, ctx?: AppContext) => {
const isMobile = ctx?.device !== "desktop";
const ext = ctx?.salesforce?.cartExtension?.[0];
return { ...props, isMobile, activeCrossellCart: ext?.active ?? false };
};ctx?: AppContextoptional + optional-chaining on every read.useDevice()(from@decocms/start/sdk/useDevice) in components instead ofctx.device.- Heavy
ctx.invoke.*data fetching removed from the section loader (kept to cheap prop derivation). - SEO sections rewritten to import
renderTemplateString/SEOSectionfrom@decocms/apps/website/components/Seoand inline the title/description/canonical normalization (nodefaultLoader/DefaultProps).
Proposed fix (in the migrate transform)
Make scripts/migrate.ts emit start-compatible loaders automatically:
- Rewrite loader signatures to
(props, req, ctx?: AppContext)and optional-chain allctx.*reads (ctx?.x, with?? fallback). - Convert
ctx.deviceusage in components to theuseDevice()hook. - For
ctx.invoke.*heavy fetches inside section loaders, port to the start invoke/server-fn pattern (or move off the section loader). - Convert deco.cx SEO sections (
defaultLoader/DefaultProps) to the@decocms/apps/website/components/Seohelpers.
Alternatively / additionally, sectionLoaders.ts could pass a partial compat ctx (device + search params + invoke) as the 3rd arg so legacy loaders degrade instead of crashing — but the optional-chaining transform above is what the working migration relies on today.
Impact
Every deco.cx → TanStack migration currently produces loaders that crash on first render (blank pages, parity impossible) until fixed by hand. This is the single highest-leverage migrate-transform gap.
Repro
Migrate any deco.cx storefront with section loaders that read ctx (e.g. a VTEX/Magento commerce site), run bun run dev, and load / — the body is empty and dev.log shows the loader ctx errors above.
Filed from the tanstack-migrator pipeline; tagged [framework?] in its cross-migration notes.
Activity
feat(cms): provide compat ctx as 3rd arg to section loaders (#305) (#347
github-actions commentedon Jul 26, 2026
🎉 This issue has been resolved in version 7.23.0 🎉
The release is available on:
blocks-v7.23.0Your semantic-release bot 📦🚀
docs(migration-skill): address review — 6 fixes across gotchas #52-#72
docs(migration-skill): farmrio-storefront wave — gotchas #52-#73, lea…