diff --git a/conversations.php b/conversations.php index 59ac3fb..79ce46a 100644 --- a/conversations.php +++ b/conversations.php @@ -2814,6 +2814,8 @@ // Si es carga inicial y el servidor devolvió vacío, pero ya teníamos mensajes, preservarlos. if (initial && Array.isArray(messages) && messages.length === 0 && Array.isArray(this.conversations) && this.conversations.length > 0) { try { if (topLoader && topLoader.parentNode) topLoader.remove(); } catch(e) {} + // Ensure container visibility is restored if it was hidden during render + try { if (container && container.dataset && container.dataset.renderHidden) { container.style.visibility = 'visible'; delete container.dataset.renderHidden; } } catch(e) {} this.loadingMessages = false; if (typeof showAlert === 'function') showAlert('No se pudieron recargar mensajes; manteniendo historial actual', 'warning'); console.warn('Initial load returned empty but existing view contains messages - preserving current conversation'); @@ -2967,6 +2969,13 @@ if (initial) { // Scroll to bottom only if the caller requested following behavior if (follow) { this.scrollToBottom(); } + // Re-show the container (we hid it before rendering to avoid jump-to-top) + try { + if (container && container.dataset && container.dataset.renderHidden) { + container.style.visibility = 'visible'; + delete container.dataset.renderHidden; + } + } catch(e) { /* ignore */ } } else if (container) { // Mantener posición: desplazar por la diferencia de heights const newScrollHeight = container.scrollHeight; @@ -3005,6 +3014,9 @@ } else { // En cargas iniciales mostramos el mensaje de error y botón de reintento (comportamiento previo) if (container) { + // Make sure it's visible again + try { if (container && container.dataset && container.dataset.renderHidden) { container.style.visibility = 'visible'; delete container.dataset.renderHidden; } } catch(e) {} + container.innerHTML = `
@@ -3040,6 +3052,8 @@ } catch (e) { console.warn('Failed to trim empty messages before render', e); } if (initial) { + // Hide the container while we rebuild the DOM to avoid a visible jump to the top + try { container.style.visibility = 'hidden'; container.dataset.renderHidden = '1'; } catch(e) {} container.innerHTML = ''; }