-
Notifications
You must be signed in to change notification settings - Fork 9
Description
Summary
This proposal introduces a feature-based block architecture inside theme-elementary to support scalable development of custom client blocks, while preserving the themeβs identity as a clean Full Site Editing (FSE) starter.
The goal is not to introduce a framework or PHP component system, but to improve internal organization so that custom blocks can grow in a structured and maintainable way across projects.
π― Problem Statement
theme-elementary currently organizes assets by file type:
assets/src/css
assets/src/js
This works for small themes. However, in client projects we typically:
- Add multiple custom blocks
- Add block-specific JS functionality
- Add block-specific CSS
- Sometimes introduce server-side rendering
- Add custom integrations (e.g., WooCommerce, dynamic data)
A block with custom JS, scoped CSS, and a render callback may require touching multiple directories. As the number of blocks grows, this increases:
- Risk of mismatched or orphaned files
- Duplication of logic
- Maintenance complexity
- Contributor cognitive load
We need scalable structure without turning the starter into a framework.
π§© Proposed Architecture (Block-First)
Introduce a feature-based block structure inside assets/src:
.
βββ assets
β βββ build
β βββ src
β βββ blocks
β β βββ example-block
β β β βββ block.json
β β β βββ edit.js
β β β βββ save.js
β β β βββ editor.css (optional)
β β β βββ style.css
β β β βββ render.php (optional)
β β βββ another-block
β β βββ ...
β β
β βββ components
β βββ css (global styles)
β βββ js (global scripts)
β
βββ inc
βββ parts
βββ patterns
βββ templates
βββ theme.json
π§ Architectural Principles
1οΈβ£ Block-First, Not Framework-First
- Each custom block lives in its own folder.
- Blocks remain fully compliant with
block.json. - No custom PHP view-layer abstraction is introduced.
- No component rendering framework is added.
2οΈβ£ render.php Decision Rule
Use render.php when block output depends on server-side data such as:
- Post meta
- WooCommerce data
- Dynamic queries
- Context-dependent rendering
If the block is static and fully defined by editor attributes, use save.js.
3οΈβ£ Component Promotion Rule
The /components directory is reserved for shared JS utilities only.
Rule:
- If logic is used by only one block β keep it inside that blockβs folder.
- If logic is used by two or more blocks β move it to
/components.
No PHP view components are introduced in the starter.
4οΈβ£ Preserve FSE Compatibility
This proposal does not:
- Modify template parts
- Change patterns structure
- Alter
theme.json - Introduce external frameworks
- Change asset registration behavior
- Replace WordPress block philosophy
The theme remains a clean FSE starter.
π Build Tooling
This architecture operates within the existing build pipeline (e.g., @wordpress/scripts).
Block assets are discovered and compiled via block.json fields such as:
editorScriptscriptstyleeditorStyle
Nested block folders are fully supported by this mechanism.
Phase 1 does not:
- Modify asset output paths
- Change block registration behavior
- Introduce new runtime dependencies
Build behavior remains unchanged.
πͺ Implementation Plan
Phase 1 β Introduce Structure
- Add
/blocksdirectory insideassets/src - Add one example block as reference
- Ensure build parity with existing setup
- No breaking changes
Phase 2 β Documentation
Add a block creation checklist covering:
- Required
block.jsonfields - Naming conventions
- When to use
render.php - When to promote shared logic to
/components - Editor vs frontend asset separation
Phase 3 β Gradual Adoption
- All future client-specific blocks follow this structure
- Existing global CSS/JS may be refactored incrementally
π Success Criteria
- At least one example block implemented in the new structure
- No increase in frontend bundle size
- No regression in Global Styles behavior
- No change in FSE template behavior
- Documentation updated with clear block creation guidelines
π¦ Expected Outcomes
- Clean scaling from 1 to 20+ custom blocks
- Reduced duplication across client projects
- Clear contributor rules that prevent architectural drift
β οΈ Non-Goals
- Introducing a PHP component rendering framework
- Replacing Gutenberg block system
- Converting the starter into an enterprise theme framework
- Breaking backward compatibility
If approved, Phase 1 will introduce the folder structure and a single example block to validate the approach before wider adoption.