- 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>
59 lines
1.6 KiB
PHP
59 lines
1.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace ROITheme\Shared\Infrastructure\Wordpress;
|
|
|
|
use ROITheme\Shared\Infrastructure\Services\CriticalCSSService;
|
|
|
|
/**
|
|
* Registra hook wp_head para inyectar CSS crítico de componentes
|
|
*
|
|
* RESPONSABILIDAD:
|
|
* - Registrar hook wp_head (priority 1) para Critical Component CSS
|
|
* - Delegar renderizado a CriticalCSSService
|
|
*
|
|
* FLUJO:
|
|
* 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>
|
|
*
|
|
* 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
|
|
*
|
|
* UBICACIÓN: Infrastructure/Wordpress
|
|
*
|
|
* @package ROITheme\Shared\Infrastructure\Wordpress
|
|
*/
|
|
final class CriticalCSSHooksRegistrar
|
|
{
|
|
public function __construct(
|
|
private readonly CriticalCSSService $criticalCSSService
|
|
) {}
|
|
|
|
/**
|
|
* Registrar hooks de WordPress
|
|
*/
|
|
public function register(): void
|
|
{
|
|
// Priority 1 = Critical Component CSS (hero, navbar, top-notification-bar)
|
|
add_action('wp_head', [$this, 'renderCriticalCSS'], 1);
|
|
}
|
|
|
|
/**
|
|
* Callback para wp_head - Critical Component CSS
|
|
*
|
|
* Ejecuta CriticalCSSService que:
|
|
* - Consulta BD por componentes con is_critical=true
|
|
* - Genera CSS usando los Renderers
|
|
* - Output: <style id="roi-critical-css">...</style>
|
|
*/
|
|
public function renderCriticalCSS(): void
|
|
{
|
|
$this->criticalCSSService->render();
|
|
}
|
|
}
|