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.
| Tier | Mechanism | Files you own |
|---|---|---|
| 1 | magenx.config.ts: flags, brand, navigation, CMS blocks | none |
| 2 | Design tokens in src/app/globals.css | none |
| 3 | Slot props on a component | none |
| 4 | src/custom/, the override layer | the whole file |
Most customisation never gets past tier 2.
Tier 3: slots
Section titled “Tier 3: slots”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} /> </> )}/>Tier 4: the override layer
Section titled “Tier 4: the override layer”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.
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:
npm run check:overrides -- --updateLimits:
- 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.