registry
The shared name-to-component table the engine consults for a few swappable parts: the product card, the product gallery and home blocks.
import { registry } from '@salla.sa/twilight-theme-engine';In plain words
Think of registry as an address book: a name on one side, a component on the other. When the engine needs "the product card", it looks up product:card and renders whatever is stored there. Store your own component under that name and every product grid uses it, without copying any engine page.
This only matters for the names the engine actually looks up, listed in the notes. Any other name changes nothing unless your own code renders it (with <Component name=…>).
Signature
const registry: ComponentRegistry registry.register(name, component): void // store; replaces and forgets any original registry.override(name, component): void // store, keeping the previous one as the original registry.resolve(name): ComponentType | null registry.getOriginal(name): ComponentType | null registry.has(name): boolean registry.list(): string[] registry.listByPrefix(prefix): string[] registry.remove(name): boolean registry.clear(): void
Try it live
import { registry } from '@salla.sa/twilight-theme-engine';
import { MyProductCard } from './components/MyProductCard';
// app/router.tsx: at module scope, before createRouter()
registry.register('product:card', MyProductCard);
registry.override('product:card', MyProductCard);
// Where the engine renders <ProductCard product={…} /> (grids, sliders, listings),
// MyProductCard receives the same props, but only after both calls.
Example
import { registry } from '@salla.sa/twilight-theme-engine';
import { createRouter } from '@salla.sa/twilight-theme-engine/tanstack';
import { MyProductCard } from './components/MyProductCard';
import { routeTree } from './routeTree.gen';
// Both calls: ProductCard only honours an override that has an original.
registry.register('product:card', MyProductCard);
registry.override('product:card', MyProductCard);
export function getRouter() {
return createRouter(routeTree);
}
How it behaves
Names the engine resolves:
product:card(everyProductCard),product:gallery(ProductGallery),account:layout-pending(the account layout while it loads) andhome:<path>, tried ashome:<path>:<view_style>first (home blocks, registered withregisterHomeComponents()from/routes/home).Register at module scope in
app/router.tsx, beforecreateRouter(). The registry is a module-level object: on the server one copy is shared by every request, so never register per request or per render.ProductCardandProductGallerylook their key up once per mounted instance (useMemowith no dependencies); a registration made later reaches only instances mounted after it.product:galleryneeds no seed:ProductGalleryrenders whatever the key resolves to, unless that isProductGalleryitself.
Gotchas
product:cardneedsregisterand thenoverride.ProductCarduses the key only whenregistry.getOriginal('product:card')is notnull(src/components/product/ProductCard.tsx), andoverrideon an empty key records no original. Withoverridealone the default card keeps rendering, with no warning.Names are colon-separated.
header,footer,product.cardorcart.itemregister without complaint and change nothing: the engine imports those parts directly.You cannot wrap the default card. The engine never stores it under
product:card, souseOriginalComponent('product:card')inside your override returns your own seed, and rendering it recurses until React gives up. Treat the override as a full replacement.
Related
Renders the component registered under a name, passing every other prop to it, or a fallback when nothing is registered there.
useComponentReturn the component registered under a name, or the one it replaced, so you render it yourself with typed props.
defineComponentRegisters a component under a name when its file loads, and returns the same component so it can also be imported and rendered directly.
registerComponents, overrideComponentsRegister or override many named components in one call, from an object whose keys are names and whose values are components.