Component Schema: The Complete Guide
Introduction
In the Weaverse ecosystem, a component’s schema is the critical link between code and the visual editor. The schema defines how components appear in the Weaverse Studio, what customization options are available, and how components interact with each other. Think of it as both a blueprint and an interface that empowers developers and merchants alike.Component Registration Method
Weaverse components are registered using static exports and configuration. Static Export PatternThe createSchema() Function
Weaverse provides thecreateSchema()
function as the modern, recommended way to define component schemas. This function offers several advantages over the traditional manual type definition approach:
Why Use createSchema()?
- Runtime Validation: Validates your schema configuration at build time using Zod, catching errors before they reach production
- Type Safety: Provides excellent TypeScript inference and autocompletion
- Consistent Standards: Ensures all schemas follow the same validation rules
- Future-Proof: Ready for new schema features and validation rules
Basic Usage
createSchema()
function takes a schema object and returns a validated schema that Weaverse can use. If your schema has any validation errors, you’ll get clear error messages at build time.
Import Options
You can importcreateSchema
from either package:
Anatomy
TheHydrogenComponentSchema
acts as a comprehensive definition for your component, specifying everything from its appearance in the editor to its behavior within the theme. This schema-driven approach ensures consistency, predictability, and a seamless user experience.
Core Schema Structure
The modern way to define component schemas is using thecreateSchema()
function, which provides runtime validation and type safety:
createSchema()
function:
- Validates your schema at build time using Zod validation
- Provides better TypeScript inference and error messages
- Catches configuration errors early before they reach the editor
- Ensures consistency across all component schemas
⚠️ Migration Notice: TheEach property serves a specific purpose in defining how your component behaves in the Weaverse ecosystem. Let’s explore each in detail.inspector
property has been deprecated in favor ofsettings
. Whileinspector
is still supported for backward compatibility, new components should usesettings
. The Weaverse system automatically handles both properties during the transition period.
Essential Properties
title
and type
title
The title
property defines the human-readable name for your component. This name appears in the Weaverse Studio’s Page Outline section and component browser, making it crucial for discoverability and usability.
Best Practices:
- Keep titles concise but descriptive (generally 1-3 words)
- Use Title Case for consistency
- Reflect the component’s purpose or functionality
- Avoid technical jargon that merchants might not understand

type
The type
property serves as a unique identifier for your component within the Weaverse ecosystem. This property is used internally to differentiate between components and must be unique across your entire theme.
Under the Hood:
When components are registered with Weaverse, they’re stored in a registry using this type
as the key. The WeaverseHydrogen.registerElement()
method uses this key to map components to their schemas and loaders.
Best Practices:
- Use kebab-case (e.g.,
product-card
,hero-banner
) - Make it descriptive of the component’s function
- Keep it concise but clear
- Ensure uniqueness across all components
settings
settings
property defines what customization options are available to users in the Weaverse Studio. It’s organized into groups that appear as collapsible sections in the editor interface.
Note: This property was previously calledinspector
and that name is still supported for backward compatibility. However, new components should usesettings
as the canonical property name.
Settings Group Structure
-
group
: A label that categorizes a set of related inputs. Common groups include “Content”, “Style”, “Settings”, etc. -
inputs
: An array of input configurations that determine the UI controls available for customization.
settings
property is used by the Weaverse Studio to generate the UI controls. When a user changes a value in the settings panel, the Weaverse Studio updates the component’s data, which triggers a re-render with the new values.
The schema also influences data initialization. The generateDataFromSchema
utility function extracts default values from your schema to create the initial state of a component when it’s added to a page.
Best Practices:
- Organize inputs logically by grouping related controls
- Keep group names consistent across components
- Place frequently used settings in the most accessible groups
- Follow a consistent order (e.g., Content → Style → Settings → Advanced)
Component Relationships
childTypes
childTypes
property determines which components can be nested inside the current component. This creates a parent-child relationship that affects both the component hierarchy and the user interface in Weaverse Studio.
When a user tries to add a child component through the editor, only components with types listed in childTypes
will be available as options. If childTypes
is not specified, the component won’t accept any children.
Under the Hood:
The Weaverse engine uses the childTypes
array to filter the available components when a user tries to add a child component. This relationship also influences how data is structured and how components are rendered in the DOM.
Best Practices:
- Only include child types that make logical sense for your component
- Consider the layout and design implications of nested components
- Keep the list focused to avoid overwhelming users with too many options
- Ensure all specified child types exist in your component library
presets
presets
property defines the default configuration and child components when a component is first added to a page. This ensures a polished, ready-to-use experience for users and reduces setup time.
HydrogenComponentPresets Structure
presets
property to initialize the component’s data. This includes creating any child components specified in the children
array. The data is then passed to the component as props at render time.
Best Practices:
- Design presets with real-world usage in mind
- Include sensible defaults for all important properties
- Pre-configure child components for a complete experience
- Test presets in various contexts to ensure they’re versatile
Component Limitations and Placement
limit
limit
property restricts how many instances of a component can exist within its parent container. If no parent exists, the limit applies to the entire page. This is useful for components that should appear only once or a few times for design or performance reasons.
Under the Hood:
When a user tries to add a component, the Weaverse Studio checks the current count of instances against the limit
property. If the limit is reached, the component is disabled in the add component UI.
Common Use Cases:
- Limiting header/footer components to one per section
- Restricting promotional banners to prevent overwhelming users
- Controlling resource-intensive components for performance
- Maintaining design coherence by limiting competing elements
enabledOn
enabledOn
property controls where components can be used within a theme.
Note to users: Thegroups
feature for managing components in header/footer sections is not available yet. Currently, only thepages
property is functional. Thegroups
feature will be implemented in a future release.
Page Types
Thepages
array specifies which page types can include this component. Use '*'
to allow the component on all page types.
Data Flow and Component Lifecycle
Understanding how data flows through the component schema system is crucial for effective component development.Schema to Component Data Flow
- Schema Registration: When you define a component’s schema, you’re creating a blueprint for both its UI representation and data structure.
-
Data Initialization: When a component is added to a page, the
generateDataFromSchema
utility extracts default values from your schema to create the initial data state. - Preset Application: If presets are defined, they’re applied on top of the default schema values.
- User Customization: When a user changes settings in the settings panel, those values are saved to the component’s data.
- Component Rendering: The component receives its data as props when rendered, allowing it to display the appropriate UI based on user customizations.
Dynamic Inputs with Conditions
Thecondition
property in inputs allows you to create dynamic UIs that respond to user choices. The Weaverse engine supports two types of conditions:
- String-based conditions using the format
bindingName.operator.value
(Deprecated) - Function-based conditions that can perform more complex logic (Recommended)
Note to users: String-based conditions are deprecated. For new components, we strongly recommend using function-based conditions which offer more flexibility and better type safety.
Complete Example
Let’s look at a comprehensive, real-world example of a component schema:Advanced Features
Data Revalidation
TheshouldRevalidate
property on input settings allows you to trigger data reloading when certain inputs change. This is useful for inputs that affect the data fetched by a component’s loader function.
Custom Heading Inputs
The schema system supports special heading inputs that don’t represent data, but help organize the settings UI with section titles.Common Patterns and Best Practices
Organizing Settings Groups
A consistent approach to settings groups improves usability:- Content: Text, images, and other primary content
- Style: Visual presentation, colors, typography, layouts
- Settings: Configuration options, functional settings
- Advanced: Technical options, performance settings
Conditional Logic
Use thecondition
property in inputs to create dynamic UI that responds to user choices:
Schema Composition
For complex components, consider decomposing schemas:Migration Guide
Migration from Inspector to Settings
If you have existing components using theinspector
property, here’s how to migrate them:
1. Simple Rename
Migration to createSchema()
The modern approach uses thecreateSchema()
function instead of manual type definitions:
1. Update Imports
2. Wrap Schema with createSchema()
- ✅ Runtime validation catches errors early
- ✅ Better TypeScript inference and autocomplete
- ✅ Consistent validation across all schemas
- ✅ Future-proof for new schema features
3. Gradual Migration
During the transition period, you can keep both properties. The system will usesettings
as the primary source and fall back to inspector
if settings
is not available:
settings
will be used. The inspector
property is ignored to prevent duplication.
Troubleshooting
Common Schema Issues
-
Schema Validation Errors: When using
createSchema()
, you may encounter validation errors at build time. These errors provide clear messages about what’s wrong with your schema configuration. Common validation issues include:- Missing required fields (
title
,type
) - Invalid input types
- Malformed configuration objects
- Missing required fields (
-
Duplicate Type Error: Each component must have a unique
type
. Check for duplicates across your entire theme. -
Missing Required Properties: Ensure all required properties (
title
,type
) are defined. ThecreateSchema()
function will catch these at build time. -
Invalid Input Types: Verify that all input
type
values match those supported by Weaverse. The validation will show allowed types if you use an invalid one. -
Child Component Not Available: If a child component doesn’t appear in the editor, check that its type is included in the parent’s
childTypes
array. -
Component Not Appearing on Specific Pages: Verify that the
enabledOn.pages
array includes the intended page types. -
Data Not Refreshing: For components with loaders, check if relevant inputs have
shouldRevalidate: true
set to trigger data refetching. - Schema Changes Not Reflecting: Remember that schema changes require a server restart to take effect in development mode.
-
Deprecation Warnings: If you see warnings about the
inspector
property, update your schema to usesettings
instead. -
Type Errors with createSchema(): If you’re getting TypeScript errors, ensure you’re importing
createSchema
correctly and that your schema object matches the expected structure.
Related Resources
- Input Settings Guide: Detailed information on all available input types
- Weaverse Component Guide: Comprehensive guide to creating components
- Example Components: Collection of sample components for reference
Conclusion
TheHydrogenComponentSchema
is the foundation of your component’s interaction with the Weaverse ecosystem. A well-designed schema creates an intuitive editing experience, ensures components are used appropriately, and provides the flexibility merchants need.
By understanding the properties and patterns described in this guide, you can create components that are both powerful for developers and accessible to merchants. Remember to use settings
for new components and migrate existing inspector
properties when convenient.