This commit is contained in:
2025-09-03 15:23:32 -03:00
parent cf571cbc14
commit 6ebe62ef87
2 changed files with 22 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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 <div data-elecciones-widget="...">.');
}
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(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
@@ -75,6 +85,8 @@ if (import.meta.env.DEV) {
</QueryClientProvider>
</React.StrictMode>
);
} 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.');
}