Skip to content

Customising a fork

A fork that edits src/ directly owns every edited file forever: each upstream release becomes a manual merge. Four tiers avoid that. Work down the list and stop at the first tier that can express the change.

TierMechanismFiles you own
1magenx.config.ts: flags, brand, navigation, CMS blocksnone
2Design tokens in src/app/globals.cssnone
3Slot props on a componentnone
4src/custom/, the override layerthe whole file

Most customisation never gets past tier 2.

A component exposes named regions as render props and keeps the logic around them. ProductCard has renderBadges, renderQuickActions and renderFooter. Each slot receives what the card already worked out (stock, discount, deal, best-seller placement), so an override never recomputes rules that could drift. The defaults are exported, so a slot that only adds something composes around them:

<ProductCard
product={product}
renderBadges={(context) => (
<>
<ProductCardBadges {...context} />
<EcoBadge sku={context.product.sku} />
</>
)}
/>

The theme’s @/* import path tries src/custom/ first, then src/. A file at src/custom/<path> therefore replaces src/<path> everywhere it is imported, and deleting it restores upstream.

yesno

import '@/components/commerce/product-card'

src/custom/components/
commerce/product-card.tsx
exists?

Your override

src/components/commerce/product-card.tsx

A whole-file copy goes stale quietly when upstream changes the original. Each override records a hash of its upstream file in src/custom/overrides.lock.json, and npm run check:overrides fails when upstream has moved. Read the upstream change, update your override, then re-baseline:

Terminal window
npm run check:overrides -- --update

Limits:

  • Routes can’t be overridden. Next.js finds src/app/** by file path, not through the import alias. Keep route files thin and put the substance in components, which can be overridden.
  • One override per file. Two parties can’t both override the same module.