faststore-overrides
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFastStore Section & Component Overrides
FastStore 区块与组件覆盖
When this skill applies
本技能的适用场景
Use this skill when:
- You need to customize the behavior or appearance of a FastStore storefront component beyond what theming and design tokens can achieve.
- You need to replace a native component entirely with a custom implementation.
- You need to inject custom logic or modify props on native components within a section.
- You are working with files in .
src/components/overrides/
Do not use this skill for:
- Visual-only changes (colors, typography, spacing) — use the skill and design tokens instead.
faststore-theming - Building custom state management for cart, session, or search — use the skill.
faststore-state-management - Extending the GraphQL data layer — use the skill.
faststore-data-fetching
本技能适用于以下场景:
- 你需要对FastStore店铺前端组件进行定制,且定制需求超出了主题和设计令牌的能力范围。
- 你需要用自定义实现完全替换原生组件。
- 你需要在某个区块内的原生组件中注入自定义逻辑或修改props。
- 你正在处理目录下的文件。
src/components/overrides/
本技能不适用于以下场景:
- 仅视觉层面的修改(颜色、排版、间距)——请使用技能和设计令牌。
faststore-theming - 为购物车、会话或搜索构建自定义状态管理——请使用技能。
faststore-state-management - 扩展GraphQL数据层——请使用技能。
faststore-data-fetching
Decision rules
决策规则
- Use overrides when theming alone cannot achieve the desired change (e.g., replacing a component, adding logic, changing behavior).
- Use the map with
componentswhen replacing a native component entirely.{ Component: CustomComponent } - Use the map with
componentswhen only changing props on a native component without replacing it.{ props: { ... } } - Use the option on
classNamefor wrapper-level styling alongside behavioral changes.getOverriddenSection() - Prefer theming with design tokens for purely visual changes — overrides are heavier and more tightly coupled.
- Only override components listed as overridable in the FastStore native sections documentation. Undocumented component names are silently ignored.
- Components prefixed with can be overridden but their props are not accessible and may change without notice.
__experimental
- 当仅靠主题定制无法实现预期修改时(例如替换组件、添加逻辑、更改行为),使用覆盖方案。
- 当需要完全替换原生组件时,使用映射并配置
components。{ Component: CustomComponent } - 当仅需修改原生组件的属性而不替换组件时,使用映射并配置
components。{ props: { ... } } - 当需要在修改行为的同时进行容器级样式调整时,在中使用
getOverriddenSection()选项。className - 对于纯视觉修改,优先使用设计令牌进行主题定制——覆盖方案更重且耦合性更强。
- 仅能覆盖FastStore原生区块文档中列出的可覆盖组件。未记录的组件名称会被静默忽略。
- 前缀为的组件可以被覆盖,但它们的props不可访问,且可能会无预警地变更。
__experimental
Hard constraints
硬性约束
Constraint: Use the Override API — Never Modify FastStore Core
约束:使用覆盖API——切勿修改FastStore核心代码
MUST use from to customize sections. MUST NOT directly modify files in or import internal source files.
getOverriddenSection()@faststore/corenode_modules/@faststore/Why this matters
Modifying is ephemeral (changes are lost on ) and importing from internal paths like creates tight coupling to implementation details that can break on any FastStore update.
node_modulesnpm install@faststore/core/src/Detection
If you see imports from (internal source paths) → STOP. These are private implementation details. Only import from the public API: and . If you see direct file edits in → STOP immediately and use the override system instead.
@faststore/core/src/@faststore/core@faststore/core/experimentalnode_modules/@faststore/Correct
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
import CustomProductTitle from '../CustomProductTitle'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
ProductTitle: { Component: CustomProductTitle },
},
})
export default OverriddenProductDetailsWrong
typescript
// WRONG: Importing from internal source paths
import { ProductDetails } from '@faststore/core/src/components/sections/ProductDetails'
// This path is an implementation detail that can change without notice.
// It bypasses the public API and will break on FastStore updates.
// WRONG: Modifying node_modules directly
// Editing node_modules/@faststore/core/dist/components/ProductDetails.js
// Changes are lost on every npm install and cannot be version-controlled.必须使用中的来定制区块。严禁直接修改中的文件或导入内部源文件。
@faststore/coregetOverriddenSection()node_modules/@faststore/重要性说明
修改中的内容是临时的(执行后更改会丢失),而从这类内部路径导入会与实现细节产生强耦合,FastStore的任何更新都可能导致代码失效。
node_modulesnpm install@faststore/core/src/问题检测
如果发现从(内部源路径)导入的代码→立即停止。这些是私有实现细节。只能从公开API导入:和。如果发现直接编辑中的文件→立即停止,改用覆盖系统。
@faststore/core/src/@faststore/core@faststore/core/experimentalnode_modules/@faststore/正确示例
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
import CustomProductTitle from '../CustomProductTitle'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
ProductTitle: { Component: CustomProductTitle },
},
})
export default OverriddenProductDetails错误示例
typescript
// 错误:从内部源路径导入
import { ProductDetails } from '@faststore/core/src/components/sections/ProductDetails'
// 该路径是实现细节,可能会无预警变更。
// 这种方式绕过了公开API,FastStore更新时会失效。
// 错误:直接修改node_modules
// 编辑node_modules/@faststore/core/dist/components/ProductDetails.js
// 更改会在每次执行npm install时丢失,且无法进行版本控制。Constraint: Override Files Must Live in src/components/overrides/
约束:覆盖文件必须放在src/components/overrides/目录下
MUST place override files in the directory, named after the section being overridden (e.g., ).
src/components/overrides/ProductDetails.tsxWhy this matters
FastStore's build system scans to discover and apply section overrides. Files placed elsewhere will not be detected and the override will silently fail — the native section will render instead with no error message.
src/components/overrides/Detection
If you see override-related code (calls to ) in files outside → warn that the override will not be applied. Check that the filename matches a valid native section name from the FastStore section list.
getOverriddenSectionsrc/components/overrides/Correct
typescript
// src/components/overrides/Alert.tsx
// File is in the correct directory and named after the Alert section
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
import CustomIcon from '../CustomIcon'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
components: {
Icon: { Component: CustomIcon },
},
})
export default OverriddenAlertWrong
typescript
// src/components/MyCustomAlert.tsx
// WRONG: File is NOT in src/components/overrides/
// FastStore will NOT discover this override.
// The native Alert section will render unchanged.
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
components: {
Icon: { Component: CustomIcon },
},
})
export default OverriddenAlert必须将覆盖文件放在目录中,文件名与要覆盖的区块名称一致(例如)。
src/components/overrides/ProductDetails.tsx重要性说明
FastStore的构建系统会扫描目录来发现并应用区块覆盖。放在其他位置的文件不会被检测到,覆盖会静默失效——原生区块会正常渲染,且不会有错误提示。
src/components/overrides/问题检测
如果在目录外的文件中发现与覆盖相关的代码(调用)→警告该覆盖不会生效。检查文件名是否与FastStore区块列表中的有效原生区块名称一致。
src/components/overrides/getOverriddenSection正确示例
typescript
// src/components/overrides/Alert.tsx
// 文件在正确的目录中,且以Alert区块命名
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
import CustomIcon from '../CustomIcon'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
components: {
Icon: { Component: CustomIcon },
},
})
export default OverriddenAlert错误示例
typescript
// src/components/MyCustomAlert.tsx
// 错误:文件不在src/components/overrides/目录下
// FastStore不会发现此覆盖。
// 原生Alert区块会保持不变地渲染。
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
components: {
Icon: { Component: CustomIcon },
},
})
export default OverriddenAlertConstraint: Override Only Documented Overridable Components
约束:仅覆盖有文档记录的可覆盖组件
MUST only override components listed as overridable in the FastStore native sections documentation. Components prefixed with can be overridden but their props are not accessible.
__experimentalWhy this matters
Attempting to override a component not listed as overridable will silently fail. The override configuration will be ignored and the native component will render. Components marked have unstable prop interfaces that may change without notice.
__experimentalDetection
If you see a component name in the override map that does not appear in the FastStore list of overridable components for that section → warn that this override may not work. If the component is prefixed with → warn about inaccessible props and instability.
components__experimentalCorrect
typescript
// src/components/overrides/ProductDetails.tsx
// ProductTitle is a documented overridable component of ProductDetails section
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
ProductTitle: {
props: {
refNumber: true,
showDiscountBadge: false,
},
},
},
})
export default OverriddenProductDetailsWrong
typescript
// src/components/overrides/ProductDetails.tsx
// "InternalPriceCalculator" is NOT a documented overridable component
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
// This component name does not exist in the overridable list.
// The override will be silently ignored.
InternalPriceCalculator: { Component: MyPriceCalculator },
},
})
export default OverriddenProductDetails只能覆盖FastStore原生区块文档中列出的可覆盖组件。前缀为的组件可以被覆盖,但它们的props不可访问。
__experimental重要性说明
尝试覆盖未记录为可覆盖的组件会静默失效。覆盖配置会被忽略,原生组件会正常渲染。标记为的组件其属性接口不稳定,可能会无预警变更。
__experimental问题检测
如果在覆盖映射中发现的组件名称未出现在FastStore对应区块的可覆盖组件列表中→警告该覆盖可能无法生效。如果组件前缀为→警告其props不可访问且存在不稳定性。
components__experimental正确示例
typescript
// src/components/overrides/ProductDetails.tsx
// ProductTitle是ProductDetails区块中有文档记录的可覆盖组件
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
ProductTitle: {
props: {
refNumber: true,
showDiscountBadge: false,
},
},
},
})
export default OverriddenProductDetails错误示例
typescript
// src/components/overrides/ProductDetails.tsx
// "InternalPriceCalculator"不是有文档记录的可覆盖组件
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
// 该组件名称不在可覆盖列表中。
// 此覆盖会被静默忽略。
InternalPriceCalculator: { Component: MyPriceCalculator },
},
})
export default OverriddenProductDetailsPreferred pattern
推荐模式
Recommended file layout:
text
src/
├── components/
│ ├── overrides/
│ │ ├── ProductDetails.tsx ← override file (named after section)
│ │ ├── Alert.tsx
│ │ └── simple-alert.module.scss
│ ├── CustomBuyButton.tsx ← custom component
│ └── BoldIcon.tsxMinimal override — replace a component:
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
import CustomBuyButton from '../CustomBuyButton'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
BuyButton: { Component: CustomBuyButton },
},
})
export default OverriddenProductDetailsOverride props without replacing the component:
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
BuyButton: {
props: {
size: 'small',
iconPosition: 'left',
},
},
},
})
export default OverriddenProductDetailsOverride with custom styling:
typescript
// src/components/overrides/Alert.tsx
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
import styles from './simple-alert.module.scss'
import BoldIcon from '../BoldIcon'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
className: styles.simpleAlert,
components: {
Icon: { Component: BoldIcon },
},
})
export default OverriddenAlert推荐的文件结构:
text
src/
├── components/
│ ├── overrides/
│ │ ├── ProductDetails.tsx ← 覆盖文件(以区块命名)
│ │ ├── Alert.tsx
│ │ └── simple-alert.module.scss
│ ├── CustomBuyButton.tsx ← 自定义组件
│ └── BoldIcon.tsx最小化覆盖——替换组件:
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
import CustomBuyButton from '../CustomBuyButton'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
BuyButton: { Component: CustomBuyButton },
},
})
export default OverriddenProductDetails覆盖属性但不替换组件:
typescript
// src/components/overrides/ProductDetails.tsx
import { getOverriddenSection } from '@faststore/core'
import { ProductDetailsSection } from '@faststore/core'
const OverriddenProductDetails = getOverriddenSection({
Section: ProductDetailsSection,
components: {
BuyButton: {
props: {
size: 'small',
iconPosition: 'left',
},
},
},
})
export default OverriddenProductDetails带自定义样式的覆盖:
typescript
// src/components/overrides/Alert.tsx
import { getOverriddenSection } from '@faststore/core'
import { AlertSection } from '@faststore/core'
import styles from './simple-alert.module.scss'
import BoldIcon from '../BoldIcon'
const OverriddenAlert = getOverriddenSection({
Section: AlertSection,
className: styles.simpleAlert,
components: {
Icon: { Component: BoldIcon },
},
})
export default OverriddenAlertCommon failure modes
常见失败模式
- Monkey-patching or using
node_modules/@faststore/for changes the override system supports. Changes are lost on install and create maintenance burden.patch-package - Using CSS to force visual changes instead of the override API for behavioral changes or design tokens for visual changes.
!important - Creating wrapper components around native sections instead of using . Wrappers bypass CMS integration, analytics tracking, and section discovery.
getOverriddenSection() - Placing override files outside — they will be silently ignored.
src/components/overrides/ - Overriding a component name not listed in the FastStore overridable components documentation — the override is silently ignored.
- 对覆盖系统支持的修改,采用猴子补丁修改或使用
node_modules/@faststore/。更改会在安装时丢失,且增加维护负担。patch-package - 使用CSS 强制修改视觉效果,而非针对行为变更使用覆盖API或针对视觉变更使用设计令牌。
!important - 在原生区块外创建包装组件,而非使用。包装组件会绕过CMS集成、分析跟踪和区块发现功能。
getOverriddenSection() - 将覆盖文件放在目录外——会被静默忽略。
src/components/overrides/ - 覆盖FastStore可覆盖组件文档中未列出的组件名称——覆盖会被静默忽略。
Review checklist
审核检查清单
- Is the override file located in and named after the target section?
src/components/overrides/ - Does the file use from
getOverriddenSection()?@faststore/core - Are all overridden component names documented as overridable for that section?
- Are imports only from or
@faststore/core(not internal source paths)?@faststore/core/experimental - Could this change be achieved with design tokens instead of an override?
- Does the override export as default?
- 覆盖文件是否位于目录下,且与目标区块同名?
src/components/overrides/ - 文件是否使用了中的
@faststore/core?getOverriddenSection() - 所有被覆盖的组件名称是否都是对应区块中有文档记录的可覆盖组件?
- 导入是否仅来自或
@faststore/core(而非内部源路径)?@faststore/core/experimental - 该变更是否可以通过设计令牌而非覆盖实现?
- 覆盖是否以默认导出的形式对外暴露?
Reference
参考资料
- Overrides overview — Introduction to the FastStore override system and when to use it
- getOverriddenSection function — API reference for the core override function
- Override native components and props — Step-by-step guide for overriding component props
- Override a native component — Guide for replacing a native component entirely
- List of native sections and overridable components — Complete reference of which components can be overridden per section
- Creating a new section — Guide for creating custom sections when overrides are insufficient
- Troubleshooting overrides — Common issues and solutions when overrides don't work
- — Related skill for visual customizations that don't require overrides
faststore-theming
- 覆盖概览 — FastStore覆盖系统介绍及适用场景
- getOverriddenSection函数 — 核心覆盖函数的API参考
- 覆盖原生组件与属性 — 覆盖组件属性的分步指南
- 覆盖原生组件 — 完全替换原生组件的指南
- 原生区块与可覆盖组件列表 — 各区块可覆盖组件的完整参考
- 创建新区块 — 当覆盖无法满足需求时,创建自定义区块的指南
- 覆盖问题排查 — 覆盖不生效时的常见问题及解决方案
- — 适用于无需覆盖的视觉定制需求的相关技能
faststore-theming