Skip to content

fix: backend: make scrollToAnchor() robust against late layout shifts#6555

Merged
gharlan merged 4 commits into
redaxo:5.xfrom
aeberhard:patch-1
Jun 26, 2026
Merged

fix: backend: make scrollToAnchor() robust against late layout shifts#6555
gharlan merged 4 commits into
redaxo:5.xfrom
aeberhard:patch-1

Conversation

@aeberhard

Copy link
Copy Markdown
Contributor

#6490 Verbesserung für JavaScript scrollToAnchor() im Backend

redaxo#6490 Verbesserung für JavaScript scrollToAnchor() im Backend
Comment thread redaxo/src/core/assets/standard.js Outdated
block: "start",
behavior: "smooth"
});
}, 200);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

250 ms liefert noch ein besseres Ergebnis, ich weiss nur nicht wie ich hier den PR noch ändern kann :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Du musst den Wert nur in deinem branch ändern

gharlan added 2 commits June 25, 2026 17:26
Use scrollIntoView() (which honors the CSS scroll-padding-top, so the sticky
navbar offset no longer needs manual correction) and defer the initial scroll
via requestAnimationFrame instead of a guessed setTimeout. Re-scroll when
still-loading images in the pjax container finish, since they shift the layout
and push the anchor out of position; stop as soon as the user scrolls manually.
@gharlan

gharlan commented Jun 25, 2026

Copy link
Copy Markdown
Member

Mich störte die fixe Timeout-Zahl, es zeigte sich ja schon in den Tests, dass nicht klar ist, welcher Wert nun benötigt wird (200ms vs 250ms etc.).

Daher habe ich Claude um Hilfe gebeten. Die Variante ist deutlich länger, aber wohl robuster. @aeberhard @ynamite @skerbis Könnt ihr einschätzen, ob die neue Variante taugt? Und bei euch mal testen? Liegt hier im PR jetzt (kann sie sonst aber auch wieder entfernen, wenn sie nicht taugt).

Hier noch eine Meldung von Claude:

Kurze Rückmeldung von mir (Claude, hab das hier zusammen mit Gregor angeschaut): Ich hab eine Variante gebaut, die ohne festen Timeout auskommt.

  • Statt der manuellen scroll-padding-top-Rechnerei jetzt scrollIntoView({block: 'start'}). Das berücksichtigt das CSS scroll-padding-top von Haus aus, der Versatz unter die Sticky-Navbar passt also automatisch (lokal getestet: der Anker landet exakt auf 75px statt dahinter).
  • Der initiale Scroll läuft über requestAnimationFrame statt setTimeout(…, 200/250) — so wird gescrollt, sobald der frisch eingetauschte pjax-Content gelayoutet ist, ohne geratene Zahl.
  • Für das eigentliche Problem (Bilder, die erst nachladen und den Anker wieder wegschieben): die noch ladenden <img> im pjax-Container werden beobachtet, und bei load/error wird nachgescrollt. Sobald man selbst scrollt, klinkt sich das wieder aus, damit es einem nicht die Seite unter dem Finger wegzieht. srcset und <picture> sind mit abgedeckt, weil gerendert immer ein <img> mit load-Event übrig bleibt.

Nicht abgedeckt sind reine CSS-Background-Bilder (verursachen aber keinen Reflow) und Font-Nachladen — falls das im Backend mal Thema wird, wäre ein ResizeObserver auf dem Container der robustere Weg.

@ynamite

ynamite commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Also in meinen ersten Tests funktioniert das sehr sauber, danke @gharlan

@aeberhard

Copy link
Copy Markdown
Contributor Author

Meine Tests sind auch erfolgreich! Sehr gut @gharlan Danke!

@gharlan gharlan linked an issue Jun 26, 2026 that may be closed by this pull request
@gharlan gharlan changed the title Verbesserung für JavaScript scrollToAnchor() im Backend fix: backend: make scrollToAnchor() robust against late layout shifts Jun 26, 2026
@gharlan gharlan added this to the REDAXO 5.21.2 milestone Jun 26, 2026
@rex-bot rex-bot added the bug label Jun 26, 2026
@gharlan
gharlan merged commit 3a84d20 into redaxo:5.x Jun 26, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Verbesserung für JavaScript scrollToAnchor() im Backend

5 participants