fix: eliminate forced reflows in TOC ScrollSpy + revert Bootstrap defer
- Replace scroll event listener with Intersection Observer in TableOfContentsRenderer - Eliminates ~100ms forced reflows from offsetTop reads during scroll - Revert Bootstrap CSS to blocking (media='all') - deferring caused CLS 0.954 - Keep CriticalBootstrapService available for future optimization - Simplify CriticalCSSHooksRegistrar to only use CriticalCSSService 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -4,28 +4,22 @@ declare(strict_types=1);
|
||||
namespace ROITheme\Shared\Infrastructure\Wordpress;
|
||||
|
||||
use ROITheme\Shared\Infrastructure\Services\CriticalCSSService;
|
||||
use ROITheme\Shared\Infrastructure\Services\CriticalBootstrapService;
|
||||
|
||||
/**
|
||||
* Registra hooks wp_head para inyectar CSS crítico
|
||||
* Registra hook wp_head para inyectar CSS crítico de componentes
|
||||
*
|
||||
* RESPONSABILIDAD:
|
||||
* - Registrar hook wp_head (priority 0) para Critical Bootstrap
|
||||
* - Registrar hook wp_head (priority 1) para Critical Component CSS
|
||||
* - Delegar renderizado a servicios especializados
|
||||
* - Delegar renderizado a CriticalCSSService
|
||||
*
|
||||
* FLUJO:
|
||||
* 1. wp_head (priority 0) → CriticalBootstrapService::render()
|
||||
* - Lee Assets/css/critical-bootstrap.css (subset ~8KB)
|
||||
* - Output: <style id="roi-critical-bootstrap">...</style>
|
||||
*
|
||||
* 2. wp_head (priority 1) → CriticalCSSService::render()
|
||||
* 1. wp_head (priority 1) → CriticalCSSService::render()
|
||||
* - Consulta BD por componentes is_critical=true
|
||||
* - Genera CSS usando Renderers
|
||||
* - Output: <style id="roi-critical-css">...</style>
|
||||
*
|
||||
* 3. Bootstrap completo se carga diferido (media="print" + onload)
|
||||
* - No bloquea renderizado inicial
|
||||
* NOTA: CriticalBootstrapService está DESHABILITADO porque diferir
|
||||
* Bootstrap causa CLS alto (0.954). Bootstrap carga bloqueante.
|
||||
*
|
||||
* PATRÓN:
|
||||
* - SRP: Solo registra hooks, delega lógica a servicios
|
||||
@@ -37,8 +31,7 @@ use ROITheme\Shared\Infrastructure\Services\CriticalBootstrapService;
|
||||
final class CriticalCSSHooksRegistrar
|
||||
{
|
||||
public function __construct(
|
||||
private readonly CriticalCSSService $criticalCSSService,
|
||||
private readonly CriticalBootstrapService $criticalBootstrapService
|
||||
private readonly CriticalCSSService $criticalCSSService
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -46,25 +39,10 @@ final class CriticalCSSHooksRegistrar
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
// Priority 0 = Critical Bootstrap (primero, antes de componentes)
|
||||
add_action('wp_head', [$this, 'renderCriticalBootstrap'], 0);
|
||||
|
||||
// Priority 1 = Critical Component CSS (después de Bootstrap)
|
||||
// Priority 1 = Critical Component CSS (hero, navbar, top-notification-bar)
|
||||
add_action('wp_head', [$this, 'renderCriticalCSS'], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback para wp_head - Critical Bootstrap
|
||||
*
|
||||
* Inyecta subset de Bootstrap (~8KB) inline:
|
||||
* - Container, flexbox, navbar, dropdown
|
||||
* - Output: <style id="roi-critical-bootstrap">...</style>
|
||||
*/
|
||||
public function renderCriticalBootstrap(): void
|
||||
{
|
||||
$this->criticalBootstrapService->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback para wp_head - Critical Component CSS
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user