Principle:AFK surf Open agent Effects Registration
| Knowledge Sources | |
|---|---|
| Domains | Editor, Web_Components, BlockSuite |
| Last Updated | 2026-10-25 00:00 GMT |
Overview
Pattern of running one-time, module-load-time side effects that register custom elements and DI providers before any consuming component is constructed.
Description
In a web-components-based editor like BlockSuite, every block, widget, and panel is a LitElement registered in the global CustomElementRegistry. Before any editor instance is created, these element definitions must exist so that the DOM parser can upgrade custom-element tags. The effects-registration pattern bundles these registrations into named effects() functions (itEffects, commentEffects) that are called at module load, alongside the construction of DI extension managers that supply store/view providers. Failing to register effects first leads to UnknownElement render failures and missing DI bindings.
Usage
Apply this principle whenever you build a web-components editor or any system that relies on a populated custom-element registry and a pre-wired DI container at first paint. Run the registrations as a side effect at module evaluation, before the main() entry point creates the application.
Theoretical Basis
The pattern relies on two guarantees:
- CustomElementRegistry side effects: customElements.define(name, ctor) is a global, idempotent registration that must occur before any DOM containing the tag is parsed.
- DI container construction: the extension managers (StoreExtensionManager, ViewExtensionManager) are constructed once and hold the provider graph; later get(scope) calls resolve extensions from this graph.
Pseudo-code:
// Module-load side effects (must run before any editor is built)
itEffects(); // defines Lit elements + block definitions
const storeManager = getTestStoreManager(); // builds the store DI graph
commentEffects(); // defines comment-app Lit elements
// Only now is it safe to construct the editor.