popScope static method
Called when a scope is disposed or becomes inactive
Implementation
static void popScope(String scopeName) {
final removed = _scopeStack.remove(scopeName);
_scopeCreationTimes.remove(scopeName);
_scopeUsesParentScope.remove(scopeName);
if (removed && ZenConfig.enableDebugLogs) {
ZenLogger.logDebug('📚 Scope stack pop: ${_formatStack()}');
// Check if we're popping back to a non-parent-scope route
final currentTopScope = getCurrentScope();
if (currentTopScope != null) {
final topScopeUsesParentScope =
_scopeUsesParentScope[currentTopScope] ?? true;
if (!topScopeUsesParentScope) {
if (ZenConfig.enableDebugLogs) {
ZenLogger.logDebug(
'🧹 Popped back to non-parent-scope route: $currentTopScope. Triggering cleanup.');
}
// Trigger cleanup when popping back to a route that doesn't use parent scope
ZenScopeManager.cleanupAllScopesExcept(currentTopScope);
}
}
}
}