From 6ebe62ef87dc6aa11409dd6373be21a5ac5969e4 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Wed, 3 Sep 2025 15:23:32 -0300 Subject: [PATCH] Fix 1523 --- Elecciones-Web/frontend/public/bootstrap.js | 7 +++++++ Elecciones-Web/frontend/src/main.tsx | 17 +++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Elecciones-Web/frontend/public/bootstrap.js b/Elecciones-Web/frontend/public/bootstrap.js index 743523e..d4c8aaa 100644 --- a/Elecciones-Web/frontend/public/bootstrap.js +++ b/Elecciones-Web/frontend/public/bootstrap.js @@ -63,8 +63,15 @@ } // 5. Una vez cargado, llamar a la función de renderizado + // 5. Una vez cargado, llamar a la función de renderizado + console.log('Bootstrap: JS principal cargado. Buscando EleccionesWidgets.render...'); + if (window.EleccionesWidgets && typeof window.EleccionesWidgets.render === 'function') { + console.log('Bootstrap: La función render() FUE ENCONTRADA. Se procederá a llamarla.'); window.EleccionesWidgets.render(); + } else { + console.error('Bootstrap: ERROR CRÍTICO - La función render() NO SE ENCONTRÓ en window.EleccionesWidgets.'); + console.log('Bootstrap: Contenido de window.EleccionesWidgets:', window.EleccionesWidgets); } } catch (error) { diff --git a/Elecciones-Web/frontend/src/main.tsx b/Elecciones-Web/frontend/src/main.tsx index b25799b..9788bcf 100644 --- a/Elecciones-Web/frontend/src/main.tsx +++ b/Elecciones-Web/frontend/src/main.tsx @@ -60,14 +60,24 @@ if (import.meta.env.DEV) { // --- MODO PRODUCCIÓN --- // Exponemos la función de renderizado para el bootstrap.js const renderWidgets = () => { - console.log('React: Se ha ejecutado renderWidgets.'); + console.log('%cReact: La función renderWidgets() ha sido EJECUTADA.', 'color: green; font-weight: bold;'); + const widgetContainers = document.querySelectorAll('[data-elecciones-widget]'); - console.log(`React: Se encontraron ${widgetContainers.length} contenedores de widget.`); + + console.log(`React: Se encontraron ${widgetContainers.length} contenedores con el atributo [data-elecciones-widget].`); + + if (widgetContainers.length === 0) { + console.warn('React: ADVERTENCIA - No se encontró ningún elemento en el DOM para renderizar un widget. Verifica que el HTML contenga
.'); + } + widgetContainers.forEach(container => { const widgetName = (container as HTMLElement).dataset.eleccionesWidget; + console.log(`React: Procesando contenedor para el widget: "${widgetName}"`); + if (widgetName && WIDGET_MAP[widgetName]) { const WidgetComponent = WIDGET_MAP[widgetName]; const root = ReactDOM.createRoot(container); + console.log(`React: Renderizando el widget "${widgetName}" en el contenedor.`); root.render( @@ -75,6 +85,8 @@ if (import.meta.env.DEV) { ); + } else { + console.error(`React: ERROR - No se encontró un componente para el nombre de widget: "${widgetName}"`); } }); }; @@ -82,4 +94,5 @@ if (import.meta.env.DEV) { (window as any).EleccionesWidgets = { render: renderWidgets }; + console.log('React: El objeto EleccionesWidgets ha sido asignado a window.'); } \ No newline at end of file