Fixed tab recreation logic and improved error handling

This commit is contained in:
2026-01-10 21:18:23 +01:00
parent 5201858b79
commit 47848bb2fd
3 changed files with 64 additions and 11 deletions

View File

@@ -120,15 +120,36 @@ class TabsManager(MultipleInstance):
if tab_config["component"] is None:
return Div("Tab content does not support serialization.")
res = InstancesManager.get(self._session, tab_config["component"][1], None)
# 1. Try to get existing component instance
res = InstancesManager.get(self._session, tab_config["component"][1], None)
if res is not None:
logger.debug(f"Component {tab_config['component'][1]} already exists")
return res
try:
logger.debug(f"Component not created yet. Need to manually create it.")
return InstancesManager.dynamic_get(self._session, tab_config["component_parent"], tab_config["component"])
except Exception as e:
logger.error(f"Error while retrieving tab content: {e}")
# 2. Get or create parent
if tab_config["component_parent"] is None:
logger.error(f"No parent defined for tab {tab_id}")
return Div("Failed to retrieve tab content.")
parent = InstancesManager.get(self._session, tab_config["component_parent"][1], None)
if parent is None:
logger.error(f"Parent {tab_config['component_parent'][1]} not found for tab {tab_id}")
return Div("Parent component not available")
# 3. If parent supports create_tab_content, use it
if hasattr(parent, 'create_tab_content'):
try:
logger.debug(f"Asking parent {tab_config['component_parent'][1]} to create tab content for {tab_id}")
content = parent.create_tab_content(tab_id)
# Store in cache
self._state.ns_tabs_content[tab_id] = content
return content
except Exception as e:
logger.error(f"Error while parent creating tab content: {e}")
return Div("Failed to retrieve tab content.")
else:
# Parent doesn't support create_tab_content, fallback to error
logger.error(f"Parent {tab_config['component_parent'][1]} doesn't support create_tab_content")
return Div("Failed to retrieve tab content.")
def _get_or_create_tab_content(self, tab_id):