registerHomeComponents, DefaultHomeComponents, registerHomeComponentConfig
The home block registry, re-exported beside the Home module: register which component draws each kind of block before any page renders.
import { registerHomeComponents, DefaultHomeComponents, registerHomeComponentConfig, AnyHomeComponent, HomeComponentConfig, HomeComponentsProps } from '@salla.sa/twilight-theme-engine/routes/home';In plain words
The Home page draws only the blocks your theme told it about. A merchant's block has a path (photos-slider, enhanced-slider…); your theme registers one component per path, and the page draws each block with the component registered for its path.
The reference theme imports registerHomeComponents and DefaultHomeComponents from /routes/home, next to Home, and calls registerHomeComponents once in app/router.tsx.
They are the very same functions and objects as in @salla.sa/twilight-theme-engine/components/home, documented in full there: registerHomeComponents, DefaultHomeComponents and registerHomeComponentConfig.
Signature
function registerHomeComponents(
components?: Record<string, AnyHomeComponent | null>, // default: DefaultHomeComponents
prefix?: string // default: 'home:'
): void;
const DefaultHomeComponents: Record<string, AnyHomeComponent | null>;
// fixed-banner, photos-slider, testimonial, store-features, youtube, square-photos,
// fixed-products, products-slider, parallax-background,
// featured-products:style1, featured-products:style2, featured-products:style3, bundle-component
function registerHomeComponentConfig(config: Record<string, HomeComponentConfig>): void;
type HomeComponentConfig = {
height?: string; // reserved before the block mounts
className?: string | ((data: HomeComponentData) => string);
id?: string | ((data: HomeComponentData) => string);
placeholder?: React.ReactNode;
};
type AnyHomeComponent = React.ComponentType<{ data: any; priority?: boolean }>;
type HomeComponentsProps = { data: HomeComponentData & { position?: number; [key: string]: unknown } };Example
import { createRouter } from '@salla.sa/twilight-theme-engine/tanstack';
import {
DefaultHomeComponents,
registerHomeComponents,
registerHomeComponentConfig,
} from '@salla.sa/twilight-theme-engine/routes/home';
import { EnhancedSlider } from './components/home';
import { routeTree } from './routeTree.gen';
registerHomeComponents({
...DefaultHomeComponents,
'enhanced-slider': EnhancedSlider,
});
registerHomeComponentConfig({
'enhanced-slider': { height: '520px', className: 's-block s-block--enhanced-slider' },
});
export function getRouter() {
return createRouter(routeTree);
}
How it behaves
Same declarations as
/components/home: importing from either path registers into the one engine registry.Each entry is registered as
home:<path>. The renderer trieshome:<path>:<view_style>first, thenhome:<path>, which is why the featured-products defaults are keyedfeatured-products:style1tostyle3.registerHomeComponentConfigmerges by path: a later call replaces a path's whole entry. For a path it covers, a theme's entry replaces the engine's built-in one; without either, the block reserves 400px and its wrapper class iss-block s-block--<path>.A
nullvalue is skipped, not unregistered:{ ...DefaultHomeComponents, youtube: null }leavesyoutubeout of that call, but a component registered for it earlier stays.
Gotchas
Not called for you: without
registerHomeComponents, the Home page draws no blocks.Call both at module scope in
app/router.tsx, not inside a component, so the server and the browser have the registrations before the first render.AnyHomeComponentdeclares apriorityprop, butHomeComponentRenderernever sets it: it passespriorityinsidedata(data.priority,truefor the first three blocks). Readdata.priorityin your block to load its first image eagerly (packages/theme-engine/src/components/home/HomePageRenderer.tsx).
Related
The store's home page: loads the blocks the merchant arranged and draws each one with the component registered for its path.
registerHomeComponentsTells the engine which component draws each home page block, by the block path the Salla API sends. Call it once at startup.
DefaultHomeComponentsThe engine's 13 built-in home blocks, keyed by block path, ready to spread into registerHomeComponents.
registerHomeComponentConfigSets the placeholder, reserved height, class and id HomeComponentRenderer uses around your own home blocks before they load.