Extension Features
Since version 3.9
Feature Hooks
The feature hooks expose different hooks to extend features of an extension.
registerFeature
A hook to register or extend a feature for an extension.
Parameters
name: string- The name of the feature. Must start with a lowercase letter. Both camelCase (e.g.,"orderDetails") and dash-case (e.g.,"root-error-meta") are acceptable. PascalCase names are not allowed.options:ExtensionFeatures- The options of the Feature
Example
./example-extension/acme-extension/index.ts
export default defineExtension({
unstable_lifecycleHooks: {
onFeaturesInit: (hooks) => {
hooks.registerFeature("acme-feature", {
flags: {
canFooBar: false,
},
ui: {
componentsMap: {
Header: new URL("./components/AcmeHeader.tsx", import.meta.url),
Toolbar: new URL("./components/AcmeToolbar.tsx", import.meta.url),
Footer: new URL("./components/AcmeFooter.tsx", import.meta.url),
},
},
});
},
},
});
Component map entry formats
Each entry in componentsMap can be one of:
| Format | Description |
|---|---|
URL | A component reference (no fragment) |
null | Disables the component |
{ component, fragment?, constraints? } | A component with an optional co-located GraphQL fragment and optional type constraints |
When using the object format:
component(URL \| null): The component reference, ornullto disablefragment(string | URL, optional): A GraphQL fragment for this component's data requirements. Pass aURLto a.gqlfile (recommended for multi-line fragments) or an inline string for small fragmentsconstraints.targetGraphQLType(string, optional): The GraphQL type this component's fragment must target. Can only be declared once per component key (first extension loaded wins).
A feature-wide constraint can also be set with
ui.constraints.targetGraphQLType to lock all component fragments to the same
type. Feature-wide and per-component constraints are mutually exclusive.
See the Components Map guide for detailed usage.