Skip to content

Commit e6b84fc

Browse files
committed
fix(animation): keep scroll direction across observers
1 parent b82bd4f commit e6b84fc

4 files changed

Lines changed: 11 additions & 23 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
- Ajout du réglage `is_lcp` à `get_the_image()` (fetchpriority high, decoding sync, pas de lazy loading)
44
- Ne jamais produire `fetchpriority="high"` avec `loading="lazy"` dans les helpers d’images
55
- Ajout des helpers `get_theme_static_image_markup()` : images statiques du thème avec width/height (CLS) et conservation de `alt=""` pour les images décoratives
6-
- Abaissement du `fetchpriority` du logo personnalisé pour ne pas concurrencer l’image LCP
76
- Ajout du filtre `bea_theme_framework_preload_fonts` (vide par défaut) pour précharger les polices above-the-fold
87
- Réécriture de `Animation` avec des IntersectionObservers partagés au lieu d’une boucle au scroll (mêmes options et callbacks)
98
- Ajout de l’utilitaire JS `deferInitialization()` pour exécuter du code non critique à idle (INP)

‎README.md‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ the_image( $image_id, [ 'alt' => '' ], [ 'size' => 'hero', 'is_lcp' => true ] );
211211
the_theme_static_image( 'dist/images/placeholder.svg', [ 'class' => 'card__image', 'loading' => 'lazy' ] );
212212
```
213213

214-
- **Custom logo**: gets `fetchpriority="low"` so it never competes with the real LCP image.
215214
- **Fonts preload**: opt-in, only for fonts rendered on first paint.
216215

217216
```php
@@ -248,7 +247,6 @@ the_image( $image_id, [ 'alt' => '' ], [ 'size' => 'hero', 'is_lcp' => true ] );
248247
the_theme_static_image( 'dist/images/placeholder.svg', [ 'class' => 'card__image', 'loading' => 'lazy' ] );
249248
```
250249

251-
- **Logo personnalisé** : reçoit `fetchpriority="low"` pour ne pas concurrencer la vraie image LCP.
252250
- **Preload des polices** : opt-in, uniquement pour les polices rendues au premier affichage.
253251

254252
```php

‎inc/Services/Performance.php‎

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function boot( Service_Container $container ): void {
2626
*/
2727
add_action( 'wp', [ $this, 'register_assets' ] );
2828
add_action( 'wp_head', [ $this, 'preload_fonts' ], 1 );
29-
add_filter( 'get_custom_logo_image_attributes', [ $this, 'deprioritize_custom_logo' ], 20 );
3029
}
3130

3231
/**
@@ -90,23 +89,6 @@ public function preload_fonts(): void {
9089
}
9190
}
9291

93-
/**
94-
* Prevent the site logo from competing with the real LCP candidate.
95-
*
96-
* @param array $custom_logo_attr Image attributes for the custom logo.
97-
*
98-
* @return array
99-
*/
100-
public function deprioritize_custom_logo( $custom_logo_attr ): array {
101-
if ( ! is_array( $custom_logo_attr ) ) {
102-
return [];
103-
}
104-
105-
$custom_logo_attr['fetchpriority'] = 'low';
106-
107-
return $custom_logo_attr;
108-
}
109-
11092
/**
11193
* Add passsive touchstart for performance
11294
* @return string

‎src/js/classes/Animation.js‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const animationClass = 'js-animation'
1010
// one IntersectionObserver per rootMargin, shared by all instances using it
1111
const observers = new Map()
1212
const lastScroll = { x: window.scrollX, y: window.scrollY }
13+
let scrollUpdateScheduled = false
1314

1415
// ----
1516
// class Animation
@@ -303,14 +304,22 @@ function getObserver(rootMargin) {
303304
/**
304305
* Scroll infos passed to callbacks, same shape as oneloop.js ScrollObserver (direction.y = 1 when scrolling down).
305306
* Computed on demand: no scroll listener is attached.
307+
* lastScroll is committed on the next animation frame so every caller in the same turn
308+
* (multiple IntersectionObservers, destroy) shares the same delta / direction.
306309
* @returns {object}
307310
*/
308311
function getScrollInfos() {
309312
const scroll = { x: window.scrollX, y: window.scrollY }
310313
const delta = { x: scroll.x - lastScroll.x, y: scroll.y - lastScroll.y }
311314

312-
lastScroll.x = scroll.x
313-
lastScroll.y = scroll.y
315+
if (!scrollUpdateScheduled) {
316+
scrollUpdateScheduled = true
317+
requestAnimationFrame(() => {
318+
lastScroll.x = window.scrollX
319+
lastScroll.y = window.scrollY
320+
scrollUpdateScheduled = false
321+
})
322+
}
314323

315324
return {
316325
scroll,

0 commit comments

Comments
 (0)