Skip to content

Commit 0ebcf18

Browse files
committed
Agrego modo debug para angular hydration y elimino la prueba del snapshot
1 parent 0a10391 commit 0ebcf18

2 files changed

Lines changed: 1 addition & 60 deletions

File tree

src/app/shared/theme-support/themed.component.ts

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -137,39 +137,6 @@ export abstract class ThemedComponent<T extends object> implements AfterViewInit
137137
this.lazyLoadSub = this.lazyLoadObs.subscribe(([simpleChanges, constructor]: [SimpleChanges, GenericConstructor<T>]) => {
138138
this.destroyComponentInstance();
139139

140-
// -- INICIO FIX PARPADEO (DOM Snapshot Hack) --
141-
let snapshotNode: HTMLElement | null = null;
142-
const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined';
143-
144-
if (isBrowser && this.themedElementContent?.nativeElement) {
145-
const originalNode = this.themedElementContent.nativeElement as HTMLElement;
146-
// Obtenemos las dimensiones y posición del elemento SSR si es válido
147-
if (typeof originalNode.getBoundingClientRect === 'function') {
148-
const rect = originalNode.getBoundingClientRect();
149-
if (rect.width > 0 && rect.height > 0) {
150-
// Clonamos el nodo entero tal como lo entregó SSR
151-
snapshotNode = originalNode.cloneNode(true) as HTMLElement;
152-
// Lo posicionamos absolutamente encapsulando su estilo
153-
snapshotNode.style.position = 'absolute';
154-
snapshotNode.style.top = `${rect.top + window.scrollY}px`;
155-
snapshotNode.style.left = `${rect.left + window.scrollX}px`;
156-
snapshotNode.style.width = `${rect.width}px`;
157-
snapshotNode.style.height = `${rect.height}px`;
158-
snapshotNode.style.margin = '0';
159-
snapshotNode.style.zIndex = '999999';
160-
snapshotNode.style.pointerEvents = 'none'; // Para evitar fallos en clicks del usuario
161-
// Usamos la variable nativa de bootstrap para el color de base (o blanco) para ocluir parpadeo posterior
162-
snapshotNode.style.backgroundColor = 'var(--bs-body-bg, #ffffff)';
163-
snapshotNode.style.overflow = 'hidden';
164-
snapshotNode.style.transition = 'opacity 0.2s ease-out';
165-
166-
// Lo inyectamos en el body para que flote independientemente de los saltos estructurales debajo
167-
document.body.appendChild(snapshotNode);
168-
}
169-
}
170-
}
171-
// -- FIN FIX PARPADEO --
172-
173140
this.compRef = this.vcr.createComponent(constructor, {
174141
projectableNodes: [this.themedElementContent.nativeElement.childNodes],
175142
});
@@ -181,35 +148,9 @@ export abstract class ThemedComponent<T extends object> implements AfterViewInit
181148
this.compRef$.next(this.compRef);
182149
this.cdr.markForCheck();
183150

184-
// -- INICIO TRACKING DE HIDRATACION Y SSR --
185-
if (isBrowser) {
186-
const targetNode = this.themedElementContent.nativeElement as HTMLElement;
187-
const componentName = this.getComponentName();
188-
const hasHydrationMarker = targetNode.hasAttribute('ngh') || targetNode.querySelector('[ngh]') !== null;
189-
const domNodesCount = targetNode.childNodes.length;
190-
191-
console.warn(`[Hydration Tracker] ThemedComponent: ${componentName}`);
192-
console.warn(` - ¿Tenía contenido el SSR original?: ${domNodesCount > 0 ? 'Sí (' + domNodesCount + ' nodos)' : 'No'}`);
193-
console.warn(` - ¿Angular intentó/logró hidratarlo antes de que lo destruyamos?: ${hasHydrationMarker ? 'SÍ (Encontramos atributo ngh)' : 'NO'}`);
194-
console.warn(` - Acción: Destruyendo el contenedor original ahora...`);
195-
}
196-
// -- FIN TRACKING --
197151

198152
this.themedElementContent.nativeElement.remove();
199153

200-
// -- INICIO REMOVER SNAPSHOT --
201-
if (snapshotNode && isBrowser) {
202-
// Damos a Angular ~100ms extra para asegurarse que el contenido dinámico
203-
// ya terminó sus ciclos internos de pintura (CSS, directivas, pipes).
204-
setTimeout(() => {
205-
if (snapshotNode && snapshotNode.style) {
206-
snapshotNode.style.opacity = '0'; // Disparo visual del rellenado
207-
}
208-
// Tras el desvanecimiento (que tarda 0.2s por el transition anterior), limpiar todo
209-
setTimeout(() => snapshotNode?.parentNode?.removeChild(snapshotNode), 250);
210-
}, 100);
211-
}
212-
// -- FIN REMOVER SNAPSHOT --
213154
});
214155
}
215156

src/modules/app/browser-app.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const browserAppConfig: ApplicationConfig = mergeApplicationConfig({
8484
providers: [
8585
provideHttpClient(withInterceptorsFromDi()),
8686
provideAnimations(),
87-
provideClientHydration(),
87+
provideClientHydration({debug: true}),
8888
importProvidersFrom(
8989
// forRoot ensures the providers are only created once
9090
Angulartics2RouterlessModule.forRoot(),

0 commit comments

Comments
 (0)