vtex-io-render-runtime-and-blocks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRender Runtime & Block Registration
渲染运行时与区块注册
When this skill applies
适用场景
Use this skill when a VTEX IO storefront component needs to be exposed to Store Framework as a block.
- Registering components in
store/interfaces.json - Mapping block names to React components
- Defining block composition and allowed children
- Reviewing whether a component is correctly wired into theme JSON
Do not use this skill for:
- shopper-facing component internals
- admin interfaces
- backend service or route design
- policy modeling
当需要将VTEX IO店面组件作为区块暴露给Store Framework时可使用本指南。
- 在中注册组件
store/interfaces.json - 将区块名称映射到React组件
- 定义区块组合规则和允许的子区块
- 检查组件是否正确接入主题JSON
以下场景不适用本指南:
- 面向消费者的组件内部逻辑
- 管理后台界面
- 后端服务或路由设计
- 策略建模
Decision rules
决策规则
- Every block visible to Store Framework must be registered in .
store/interfaces.json - Keep block names, component mapping, and composition explicit.
- The block ID used as the key in , for example
store/interfaces.json, is the same ID that storefront themes reference underproduct-reviewsinblocks.store/*.json - The field should map to the React entry name under
component, such asreact/, or a nested path such asProductReviewswhen the app structure is hierarchical.product/ProductReviews - Use intentionally when the block needs an explicit child model.
compositionmeans the component renders nested blocks throughchildren, whileprops.childrenmeans the block exposes named block slots controlled by Store Framework.blocks - is optional. For many simple blocks, declaring
compositionand, when needed,componentis enough.allowed - Use this skill for the render/runtime contract, and use storefront/admin skills for the component implementation itself.
- 所有对Store Framework可见的区块都必须在中注册。
store/interfaces.json - 区块名称、组件映射、组合规则需显式声明。
- 中作为键使用的区块ID(例如
store/interfaces.json),与店面主题在product-reviews的store/*.json下引用的ID完全一致。blocks - 字段需映射到
component目录下的React入口名称,例如react/;如果应用结构是层级化的,也可以使用嵌套路径,例如ProductReviews。product/ProductReviews - 当区块需要显式的子区块模型时,可按需使用配置:
composition表示组件通过children渲染嵌套区块,props.children表示区块暴露由Store Framework控制的命名区块插槽。blocks - 为可选配置。对于多数简单区块,声明
composition即可,必要时补充component配置。allowed - 本指南用于规范渲染/运行时契约,组件本身的实现请参考店面/管理后台相关开发指南。
Hard constraints
硬性约束
Constraint: Storefront blocks must be declared in interfaces.json
约束:店区块必须在interfaces.json中声明
Every React component intended for Store Framework use MUST have a corresponding entry.
interfaces.jsonWhy this matters
Without the interface declaration, the component cannot be referenced from theme JSON.
Detection
If a storefront React component is intended to be used as a block but has no matching interface entry, STOP and add it first.
Correct
json
{
"product-reviews": {
"component": "ProductReviews"
}
}Wrong
tsx
// react/ProductReviews.tsx exists with no interfaces.json mapping所有供Store Framework使用的React组件都必须在中有对应的注册条目。
interfaces.json重要性
没有接口声明的话,主题JSON无法引用该组件。
检测规则
如果一个店面React组件需要作为区块使用,但没有匹配的接口注册条目,请立即停止后续操作,先补充注册信息。
正确示例
json
{
"product-reviews": {
"component": "ProductReviews"
}
}错误示例
tsx
// react/ProductReviews.tsx文件存在,但没有对应的interfaces.json映射Constraint: Component mapping must resolve to real React entry files
约束:组件映射必须指向真实存在的React入口文件
The field in MUST map to a real exported React entry file.
componentinterfaces.jsonWhy this matters
Broken mapping silently disconnects block contracts from implementation.
Detection
If an interface points to a component name with no corresponding React entry file, STOP and fix the mapping.
Correct
json
{
"product-reviews": {
"component": "ProductReviews"
}
}Wrong
json
{
"product-reviews": {
"component": "MissingComponent"
}
}interfaces.jsoncomponent重要性
错误的映射会导致区块契约和实现之间悄无声息地断开连接。
检测规则
如果接口指向的组件名称没有对应的React入口文件,请立即停止后续操作,修复映射关系。
正确示例
json
{
"product-reviews": {
"component": "ProductReviews"
}
}错误示例
json
{
"product-reviews": {
"component": "MissingComponent"
}
}Constraint: Block composition must be intentional
约束:区块组合规则必须符合实际逻辑
Composition and allowed child blocks MUST match the component's actual layout and runtime expectations.
Why this matters
Incorrect composition contracts make theme usage brittle and confusing.
Detection
If or do not reflect how the component is supposed to receive children, STOP and correct the block contract.
allowedcompositionCorrect
json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "children",
"allowed": ["product-review-item"]
}
}Wrong
json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "blocks",
"allowed": []
}
}组合规则和允许的子区块必须与组件实际的布局和运行时预期匹配。
重要性
错误的组合契约会导致主题使用过程中容易出错,且难以排查。
检测规则
如果或配置没有反映组件接收子区块的实际逻辑,请立即停止后续操作,修正区块契约。
allowedcomposition正确示例
json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "children",
"allowed": ["product-review-item"]
}
}错误示例
json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "blocks",
"allowed": []
}
}Preferred pattern
推荐模式
Keep block contracts explicit in and keep block implementation concerns separate from render-runtime registration.
interfaces.jsonMinimal block lifecycle:
json
// store/interfaces.json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "children",
"allowed": ["product-review-item"]
},
"product-review-item": {
"component": "ProductReviewItem"
}
}json
// store/home.json
{
"store.home": {
"blocks": ["product-reviews"]
}
}tsx
// react/ProductReviews.tsx
export default function ProductReviews() {
return <div>...</div>
}This wiring makes the block name visible in the theme, maps it to a real React entry, and keeps composition rules explicit at the render-runtime boundary.
在中显式声明区块契约,将区块实现逻辑与渲染运行时注册逻辑分离。
interfaces.json最简区块生命周期示例:
json
// store/interfaces.json
{
"product-reviews": {
"component": "ProductReviews",
"composition": "children",
"allowed": ["product-review-item"]
},
"product-review-item": {
"component": "ProductReviewItem"
}
}json
// store/home.json
{
"store.home": {
"blocks": ["product-reviews"]
}
}tsx
// react/ProductReviews.tsx
export default function ProductReviews() {
return <div>...</div>
}这种注册方式可以让区块名称在主题中可见,映射到真实的React入口,并且在渲染运行时边界显式声明组合规则。
Common failure modes
常见错误场景
- Forgetting to register a storefront component as a block.
- Mapping block names to missing React entry files.
- Using the wrong composition model.
- 忘记将店面组件注册为区块
- 区块名称映射到不存在的React入口文件
- 使用了错误的组合模型
Review checklist
审查清单
- Is the block declared in ?
interfaces.json - Does the component mapping resolve correctly?
- Are composition and allowed children intentional?
- Is runtime registration clearly separated from component internals?
- 区块是否在中声明?
interfaces.json - 组件映射是否能正确解析?
- 组合规则和允许的子区块是否符合实际逻辑?
- 运行时注册逻辑是否与组件内部逻辑清晰分离?
Reference
参考资料
- Store Framework - Block and theme context
- Store Framework - 区块与主题上下文