Architecture: How to create deep interconnection between preview, editor, ...

Documentation for Sessions

🏗️ Architecture: How to create deep interconnection between preview, editor, ...

Date: 2026-03-11
Time: 23:36:54 UTC
Session: gspace1-205.3
Agent: angular
Confidence: 92%
Status: ✅ Documented


📋 Decision Context

Question:

How to create deep interconnection between preview, editor, and chat in vitto-studio so clicking an element in one tool immediately informs the others?

Task: Not specified


🎯 Decision Made

Chosen:

StudioInterconnectionService as single source of truth with FocusContext signal, loop prevention via source-based propagation skip, and debounced updates (150ms for UI, immediate for chat). Preview bridge client script injected into compiled HTML provides click-to-select and hover highlights via data-studio-id attributes.

Options Considered:

  1. Global event bus (Subject) — simple but no loop prevention, hard to debug
  2. StudioInterconnectionService with FocusContext signal — centralized, typed, loop-safe
  3. Direct service-to-service injection — tight coupling, circular dependency risk
  4. Redux/NGXS global state — overkill for cross-tool focus tracking

💭 Reasoning

The interconnection challenge is keeping 4 subsystems (preview, editor, chat, canvas) synchronized without infinite loops. A centralized service with a single FocusContext signal acts as source of truth. Each update carries a source: FocusSource field ('preview'|'editor'|'chat'|'canvas'|'file-tree'|'system'). When propagating to other subsystems, the originating source is skipped — this prevents A→B→A loops. Chat source gets immediate propagation (no debounce) because AI edits should reflect instantly. The preview bridge client (~100 lines injected JS) walks the DOM tree to find [data-studio-id] attributes, which the ComponentTaggingPlugin injects during rspack compilation. This Lovable-style approach maps DOM elements back to source files. New bridge message types (STUDIO_ELEMENT_SELECTED, STUDIO_HIGHLIGHT_ELEMENT, etc.) added to embeddable-bridge's BridgeMessageType union with full payload types.


📁 Files Involved


🔗 Related


Auto-generated by MCP Smart Consolidation