registerThemeHookSlots
Declares hook slot names your theme renders itself, so the Salla SDK lets marketplace apps mount content into them.
import { registerThemeHookSlots } from '@salla.sa/twilight-theme-engine/utils';In plain words
Salla marketplace apps can add content into named places on a page, called hook slots. The SDK keeps a list of the slot names it allows and refuses any other. The engine's own slots are on that list; a slot your theme invents is not.
registerThemeHookSlots('index:start') adds your names to the list. Call it once, at the top level of a file your root route imports, never inside a component.
Signature
function registerThemeHookSlots(...names: string[]): void
Try it live
// app/routes/__root.tsx: at module scope, not inside a component.
import { registerThemeHookSlots } from '@salla.sa/twilight-theme-engine/utils';
registerThemeHookSlots('index:start');
Example
import { createTwilightRootRoute } from '@salla.sa/twilight-theme-engine/tanstack';
import { registerThemeHookSlots } from '@salla.sa/twilight-theme-engine/utils';
import { RootComponent } from '../components/layout/RootComponent';
// Our ScopeSelector renders the index:start slot, which the SDK does not know about.
registerThemeHookSlots('index:start');
export const Route = createTwilightRootRoute()({
shellComponent: RootComponent,
});
How it behaves
The names go into a module-level
Set, so repeats are ignored. The engine then pushes them into the SDK'sSalla.hooks._themeSlotstwice: from an inline script in the root route's head, while the page is parsed and before any app snippet'sonReadyruns; and fromAppsSnippetsonce the SDK is ready, retrying once ontwilight::initiatedif the list does not exist yet.Registering is not rendering. The theme must still render the slot, for example with
<HookSlot name="index:start" />, which outputs Salla's hook element for apps.theme-tania registers
index:startthis way for its delivery-selector app.
Gotchas
Called inside a component, the name arrives after the head script of the page being rendered was built. Only the late browser-side push remains, and an app that mounts from its own
onReadymay already have been refused with[Hooks] Hook … is not allowed. Call it at module scope.There is no way to unregister. On the server the
Setlives as long as the process, so a name added while handling one request is in the head of every later request.
Related
Source and docs
- Engine source:
packages/theme-engine/src/utils/theme-hook-slots.ts