Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:AFK surf Open agent One Time Effect Initialization

From Leeroopedia
Knowledge Sources
Domains Extensions, Plugin_System, BlockSuite
Last Updated 2026-10-25 00:00 GMT

Overview

Pattern of running initialization exactly once per provider class (regardless of how many instances or scopes are created) via an effect() hook, used to register Lit elements and global state.

Description

View providers may override effect() to run one-time initialization that should happen before any editor instance renders. The ext-loader guarantees effect runs only once per provider class, even if the manager creates multiple instances across scopes. Typical uses are registering custom Lit elements (which must be in the global CustomElementRegistry before any DOM using them is parsed), initializing global state, and setting up shared event listeners. effect is view-provider-only; store providers have no effect hook. Keep effect idempotent since it may run across multiple manager instances.

Usage

Apply this principle when a view extension needs global, one-time setup that must precede editor rendering — registering Lit custom elements, seeding a global store, attaching window-level listeners.

Theoretical Basis

effect() is a per-class singleton initializer: effect: () → void, runs ≤ once per class. The ext-loader memoizes execution per class, so the registration side effects are deduplicated. This complements setup, which runs per (scope, options) and may execute many times.

Pseudo-code:

class MyViewProvider extends ViewExtensionProvider {
  override effect() {
    // Runs once per class, even across multiple manager instances
    registerLitElements();
    initializeGlobalState();
  }
}

Related Pages

Implemented By

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment