fix(docs): re-run home scroll-reveal after View Transitions navigation - #1215
Conversation
The home page's scroll-reveal sections (.reveal) stayed invisible (opacity:0) after navigating away from the home page and back via Astro View Transitions (e.g. home -> search -> result -> logo home). The IntersectionObserver that adds the .visible class lived in a module <script> that only evaluates once per session. Because <ViewTransitions /> swaps the DOM instead of doing a full reload, the script never re-ran on the freshly swapped-in DOM, so nothing observed the new .reveal elements. Wrap the home page script in an initHomePage() function registered on the astro:page-load event, which fires on initial load and after every View Transition navigation. This matches the existing convention already used in Search.astro and BaseLayout.astro. The reveal observer is disconnected before being recreated, and the copy-install handler is assigned via onclick to stay idempotent across re-runs. Adds Playwright coverage (docs/tests/hero-reveal.spec.mjs) for initial load, navigate-away-and-back, and reaching home via a View Transition. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🟢 Impact Analysis — PR #1215Risk tier: 🟢 LOW 📊 Summary
🎯 Risk Factors
📦 Modules Affecteddocs (2 files)
This report is generated automatically for every PR. See #733 for details. |
🛫 PR Readiness Check
PR Scope: 🔧 Infrastructure
|
| Status | Check | Details |
|---|---|---|
| ✅ | Single commit | 1 commit — clean history |
| ✅ | Not in draft | Ready for review |
| ✅ | Branch up to date | Up to date with dev |
| ❌ | Copilot review | No Copilot review yet — it may still be processing |
| ✅ | Changeset present | No source files changed — changeset not required |
| ✅ | Scope clean | No .squad/ or docs/proposals/ files |
| ✅ | No merge conflicts | No merge conflicts |
| ✅ | Copilot threads resolved | No Copilot review threads |
| ✅ | CI passing | All checks passing |
Files Changed (2 files, +104 −17)
| File | +/− |
|---|---|
docs/src/pages/index.astro |
+31 −17 |
docs/tests/hero-reveal.spec.mjs |
+73 −0 |
Total: +104 −17
This check runs automatically on every push. Fix any ❌ items and push again.
See CONTRIBUTING.md and PR Requirements for details.
There was a problem hiding this comment.
Pull request overview
Fixes a docs-site regression where home-page “scroll reveal” sections remain invisible after navigating away and back via Astro View Transitions by re-initializing the home page’s DOM-dependent logic on astro:page-load. Adds Playwright coverage to prevent regressions across initial load, away-and-back navigation, and first-time arrival to home via a View Transition.
Changes:
- Reworks the home page script to run reveal/copy setup in an
initHomePage()handler onastro:page-load, with observer teardown to avoid leaks. - Ensures the install-copy handler is idempotent across repeated inits.
- Adds Playwright regression tests that reproduce the View Transitions navigation path and assert reveal sections become visible.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| docs/src/pages/index.astro | Re-initializes the reveal IntersectionObserver (and copy button handler) on astro:page-load so newly swapped DOM is observed after View Transitions. |
| docs/tests/hero-reveal.spec.mjs | Adds regression Playwright tests covering initial load and View Transitions navigation scenarios for home-page reveal behavior. |
Summary
The home page scroll‑reveal sections (the "Why Squad?" features grid and everything below the hero) disappear and never come back after you navigate away from the home page and return to it via Astro View Transitions.
Reproduction (on the live site, https://bradygaster.github.io/squad/):
Ctrl/Cmd+K), type a query, and click a result.Root cause
BaseLayout.astroenables<ViewTransitions />(the Astro client router), so in‑site navigation swaps the DOM instead of doing a full page reload.The reveal effect works like this:
.revealelements start atopacity: 0; transform: translateY(24px)(docs/src/styles/global.css).IntersectionObserveradds the.visibleclass when they scroll into view, which animates them toopacity: 1.That observer was created in a module
<script>indocs/src/pages/index.astro. Module scripts are evaluated only once per session. When you navigate back to the home page via a View Transition, fresh.revealnodes are swapped in, but the script never re‑runs — so nothing observes the new elements and they remain atopacity: 0.Notably, the rest of the codebase already handles this correctly:
Search.astroandBaseLayout.astrore‑initialize their DOM‑dependent logic on theastro:page-loadevent (which fires on initial load and after every View Transition). The home page script was the one place that didn't follow that convention.Fix
Wrap the home page script in an
initHomePage()function registered onastro:page-load, mirroring the existing convention:IntersectionObserverisdisconnect()‑ed before being recreated, so re‑runs don't leak observers.onclick(idempotent) instead ofaddEventListener, so it can't accumulate duplicate listeners.Testing
Added
docs/tests/hero-reveal.spec.mjs(Playwright) with three cases:Test 2 fails on
devand passes with this change. Verified on a production build (astro build+astro preview) by running the exact repro flow:.revealsection after returning homeclass="… reveal",opacity = 0class="… reveal visible",opacity = 1The rest of the existing
docssuite is unaffected by this change. (Theapi-reference.spec.mjscases fail locally only because the generated API‑reference pages aren't produced outside CI; they're unrelated to this change.)Scope / follow‑up
This PR is intentionally scoped to the reported hero‑reveal regression. While investigating I noticed
Header.astrobinds its mobile‑nav / sidebar toggle in a top‑level script withoutastro:page-load, which is the same latent pattern and likely affects the mobile menu after a View Transition. That's a separate concern (different feature) and is left for a follow‑up.Files changed
docs/src/pages/index.astro— re‑run reveal/copy logic onastro:page-load.docs/tests/hero-reveal.spec.mjs— regression coverage (new).