Bugfix: Why does clicking a module tab inside Live Preview destroy t...
Documentation for Sessions
🐛 Bugfix: Why does clicking a module tab inside Live Preview destroy t...
Date: 2026-03-26
Time: 18:06:14 UTC
Session: gspace1-274.2
Agent: angular
Confidence: 95%
Status: ✅ Documented
📋 Decision Context
Question:
Why does clicking a module tab inside Live Preview destroy the entire Studio context, showing 'Untitled DRAFTING' with infinite spinner?
Task: S274: Fix Studio state destruction on Live Preview navigation (BUG-001)
🎯 Decision Made
Chosen:
Added distinctUntilChanged(spaceSlug+universeSlug) to route.paramMap subscription and an initializedContext guard in initializeFromSpace() to skip redundant re-initialization
Options Considered:
- Add click interception in preview iframe to block navigation events
- Remove allow-same-origin from iframe sandbox attributes
- Guard the router with canDeactivate to prevent navigation during preview
- Add distinctUntilChanged to paramMap subscription (chosen)
💭 Reasoning
Root cause: StudioDockShellComponent.constructor subscribes to route.paramMap without deduplication (line 180). Any router event — even identity navigation caused by iframe postMessage or Angular change detection — re-emits paramMap. This unconditionally triggers initializeFromSpace() which calls resetForUniverseSwitch() (line 489), destroying blob URLs, clearing compilation state, and resetting all preview signals. Meanwhile projectManager.loadProject() returns the project Observable again, and if slow/failing, activeProject() stays null → toolbar shows 'Untitled DRAFTING'. The fix addresses the root cause (unguarded paramMap subscription) rather than symptoms (iframe sandboxing). Click interception would be a band-aid since the issue isn't clicks escaping — it's any router emission triggering full re-init. The initializedContext guard adds defense-in-depth against any other code path that calls initializeFromSpace with same params.
📁 Files Involved
libs/libs-structural/vitto-studio/src/lib/components/studio-dock-shell/studio-dock-shell.component.ts
🔗 Related
- Decision ID:
dev_1774548374134_6tzoe53 - Session: 274
- Workspace: gspace1
Auto-generated by MCP Smart Consolidation