Skip to content

Docs search stops working after navigating via search result (View Transitions) #712

Closed

Description

@CarlosSardo

Description

The docs website search breaks after navigating to a search result. On first page load, clicking the search textbox works — the user can type and search. After clicking a search result (which triggers an Astro View Transition), the search textbox can no longer be focused or typed into. The only workaround is a hard refresh (Ctrl+F5).

Steps to Reproduce

  1. Navigate to the docs site (e.g., https://bradygaster.github.io/squad/)
  2. Click the search button or press Ctrl+K
  3. Type a query (e.g., "agent") and wait for results
  4. Click on any search result to navigate to that page
  5. Try to click the search button again or press Ctrl+K
  6. Expected: Search modal opens and the input is focused
  7. Actual: Nothing happens — search is completely non-functional

Root Cause

The Search.astro component uses a <script define:vars> block that captures DOM element references (searchBtn, searchModal, searchInput, etc.) and attaches event listeners once at initial script execution time.

The docs site uses Astro View Transitions (<ViewTransitions /> in BaseLayout.astro). After a client-side navigation, Astro swaps the DOM — replacing all the elements. The old JavaScript references now point to detached DOM nodes, so clicks/keyboard shortcuts silently do nothing.

Other components in the docs site (theme toggle, copy buttons) already handle this correctly by using document.addEventListener('astro:page-load', initFunction), but the search component was missing this pattern.

Environment

  • Astro 5.x with View Transitions enabled
  • Pagefind search integration
  • All browsers affected (View Transitions are the root cause, not browser-specific)

Activity

  1. added a commit that references this issue on Mar 31, 2026
    25e7611
  2. diberry commented on Mar 31, 2026

    @diberry
    Contributor

    🔄 Ralph status: PR #713 addresses this. Clean mergeable state, 2 files, 2 Playwright regression tests. Ready for review.

  3. diberry commented on Mar 31, 2026

    @diberry
    Contributor

    ✅ Status Update — Issue #712

    PR #713 addresses this issue (external contributor: @CarlosSardo):

    • All 21 squad members reviewed and approved
    • Re-initializes search after Astro View Transitions

    Ready for merge.

  4. added 4 commits that reference this issue on Apr 5, 2026
    77493c1
    b96ea74
    f296ff4
    9649e24
  5. added a commit that references this issue on Apr 7, 2026
    9f1e574
  6. added a commit that references this issue on Apr 13, 2026
    a91682e
  7. added 2 commits that reference this issue on Apr 21, 2026
    7de4079
    7e0774b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions