Skip to content

Regression (6.4.4): transition:persist fails to render elements containing native popover attributes #16992

Closed

Description

@sam-fakhreddine

Describe the bug

After upgrading from astro@6.4.2 to astro@6.4.4, any component using transition:persist that contains native HTML popover elements completely fails to render/persist across page navigations. The entire persisted element instantly disappears from the DOM upon client-side navigation.

Reverting the project back to 6.4.2 immediately fixes the issue and restores the persistent navigation bar.

What's the expected result?

The persisted element should remain in the DOM across navigations, exactly as it does in Astro 6.4.2 and earlier.

Steps to Reproduce

  1. Create a persistent header layout utilizing View Transitions: <header transition:persist="nav">
  2. Inside the header, include an element utilizing the native Popover API:
    <div popover id="my-menu">Menu Content</div>
    <button popovertarget="my-menu">Toggle</button>
  3. Build the site or run the dev server with astro@6.4.4.
  4. Click a link to navigate to a new page.
  5. Expected: The header persists smoothly across the navigation.
  6. Actual: The entire <header> disappears from the DOM instantly upon the route transition.

System Info

Astro: 6.4.4
Node: 22.x
Browser: Chrome / Safari
OS: macOS

Activity

  1. added
    triage: needs triage
    on Jun 7, 2026
  2. sam-fakhreddine commented on Jun 7, 2026

    @sam-fakhreddine
    Author

    I dug into the diff between 6.4.2 and 6.4.4 and the only major runtime change affecting Cloudflare deployments is the update to isNode in packages/astro/src/runtime/server/render/util.ts, which explicitly opts Cloudflare-Workers out of isNode.

    Because isNode is now false on Cloudflare, Astro switches from renderToAsyncIterable to renderToReadableStream in page.ts. It appears that renderToReadableStream is somehow dropping or mishandling the data-astro-transition-persist attributes (or the nested DOM structure) during the stream chunks when native popover attributes are present.

    A potential solution would be to either revert the isNode evaluation for Cloudflare, or ensure that renderToReadableStream flushes the persistent attributes correctly without chunking them mid-attribute.

  3. sam-fakhreddine commented on Jun 7, 2026

    @sam-fakhreddine
    Author

    I have created a Minimal Reproducible Example repository demonstrating the bug right here: https://github.com/sam-fakhreddine/astro-6.4.4-popover-persist-bug

  4. astrobot-houston commented on Jun 7, 2026

    @astrobot-houston
    Contributor
    • Reproduced: No — transition:persist with native popover elements works correctly in our automated testing across multiple scenarios.
    • Exploration: Partial — View branch
    • Unit Test: No — unable to reproduce the failure, so no failing test could be written.
    • Priority: P3: minor bug. We could not reproduce this with a minimal setup, and no transitions code changed between 6.4.2 and 6.4.4, suggesting this may be environment-specific (browser version, macOS, or project complexity). If reproducible, it would affect users combining transition:persist with the native Popover API, which is a relatively niche combination.

    We were unable to reproduce this issue. We tested transition:persist with native popover elements on Astro 6.4.4 across seven different scenarios (basic navigation, popover open during navigation, navigation via popover links, with animations, etc.) — the header persisted correctly in all cases. Notably, zero commits touched packages/astro/src/transitions/ between astro@6.4.2 and astro@6.4.4, which makes a regression between those specific versions unlikely.

    I was unable to determine the cause of this issue. To help us investigate further, could you provide a minimal reproduction repository? A few things that would help narrow this down:

    1. A GitHub repo or StackBlitz link that demonstrates the issue
    2. Your exact Chrome/Safari version (the behavior of moveBefore() — used internally by the persist mechanism — can vary between browser versions)
    3. Whether cleaning your build output (rm -rf dist node_modules/.astro) and reinstalling changes anything
    4. Whether the issue occurs in both astro dev and astro build && astro preview
    Full Triage Report

    Triage Report: Issue #16992

    Issue Details

    Title: Regression (6.4.4): transition:persist fails to render elements containing native popover attributes

    URL: #16992

    Author: sam-fakhreddine

    Labels: needs triage

    Created: 2026-06-07T23:36:39Z

    Description

    The reporter claims that after upgrading from astro@6.4.2 to astro@6.4.4, any component using transition:persist that contains native HTML popover elements completely fails to render/persist across page navigations. The entire persisted element instantly disappears from the DOM upon client-side navigation. Reverting to 6.4.2 immediately fixes the issue.

    Expected Result

    The persisted element should remain in the DOM across navigations, exactly as it does in Astro 6.4.2 and earlier.

    Steps to Reproduce (from issue)

    1. Create a persistent header layout utilizing View Transitions: <header transition:persist="nav">
    2. Inside the header, include an element utilizing the native Popover API: <div popover id="my-menu">Menu Content</div> and <button popovertarget="my-menu">Toggle</button>
    3. Build the site or run the dev server with astro@6.4.4.
    4. Click a link to navigate to a new page.
    5. Expected: The header persists smoothly across the navigation.
    6. Actual: The entire <header> disappears from the DOM instantly upon the route transition.

    System Info (from issue)

    • Astro: 6.4.4
    • Node: 22.x
    • Browser: Chrome / Safari
    • OS: macOS

    Reproduction Environment

    • Astro: 6.4.4 (from monorepo source)
    • Node: v24.15.0
    • Browser: HeadlessChrome/149.0.0.0
    • OS: Linux (CI container)

    Reproduction Attempt

    Setup

    Created a minimal reproduction in triage/gh-16992/ based on the examples/minimal template with:

    1. src/layouts/Layout.astro — A layout with <ClientRouter /> (the current name for View Transitions), a <header transition:persist="nav"> containing navigation links and a native popover element with popovertarget button.
    2. src/pages/index.astro — Home page using the layout.
    3. src/pages/about.astro — About page using the layout.

    Note: The issue mentions ViewTransitions import, but in Astro 6.x this was renamed to ClientRouter. The reproduction was adapted accordingly.

    Tests Performed

    1. Basic navigation (popover closed): Navigated from Home → About by clicking the About link. The header with popover elements persisted correctly. The heading changed from "Home Page" to "About Page" while the nav remained.

    2. Navigation with popover open: Opened the popover by clicking "Toggle Menu", then navigated by clicking a link. The header persisted correctly — the popover closed during navigation (expected behavior for popover="auto"), but the header itself remained in the DOM.

    3. Navigation via popover link: Opened the popover, then navigated by clicking a link inside the popover. The header persisted correctly.

    4. Programmatic verification: Used JavaScript to verify document.querySelector('header') and document.querySelector('[popover]') existed after navigation — both present.

    5. MutationObserver monitoring: Added a MutationObserver to track the header's DOM movements during navigation. Confirmed the expected persist flow: header removed from BODY → added to HTML (lifted for persist) → removed from HTML → added to BODY (placed back).

    6. With animations: Added transition:animate="none" on header and transition:animate="slide" on main — still worked correctly.

    7. Baseline (without popover): Tested the same setup without popover elements — transition:persist works correctly, confirming the test setup is valid.

    Code Analysis

    Examined the swapBodyElement function in packages/astro/src/transitions/swap-functions.ts, which handles transition:persist. The current implementation (introduced in commit 12ca621, Astro 6.0.0) lifts persisted elements to <html> before the body swap using moveBefore() (Chrome 133+) or appendChild() as fallback. This was added to prevent WebGL context loss on Safari.

    Key finding: No code in packages/astro/src/transitions/ was changed between astro@6.4.2 and astro@6.4.4. The moveBefore persist logic has been unchanged since Astro 6.0.0. The commits between 6.4.2 and 6.4.4 relate to routing, i18n, build optimizations, and unrelated fixes.

    Result

    Not reproduced. The transition:persist feature works correctly with native popover elements on Astro 6.4.4 in our test environment (HeadlessChrome 149, Node 24, Linux).

    Possible explanations for the reporter's issue

    1. Browser-specific behavior: The issue mentions Chrome and Safari on macOS. There may be a browser-specific interaction between moveBefore() and popover elements in a specific Chrome/Safari version that our HeadlessChrome 149 doesn't exhibit.
    2. Additional project complexity: The reporter's actual project may have additional components, frameworks, or CSS that interact with the popover in ways our minimal reproduction doesn't capture.
    3. The ViewTransitions vs ClientRouter rename: If the reporter is using ViewTransitions (the old name), they might be on a different version than they think, or there may be an import compatibility issue.
    4. Caching/build artifacts: The reporter may have stale build artifacts from a previous version causing the issue.
    5. Different popover pattern: The reporter's actual popover usage might be more complex (e.g., nested popovers, JavaScript-controlled popovers, or popover-related JavaScript that conflicts with the persist mechanism).

    No changes to transitions code between 6.4.2 and 6.4.4

    The git history shows zero commits touching packages/astro/src/transitions/ between astro@6.4.2 and astro@6.4.4, which makes the "regression" claim harder to verify. The reporter may be experiencing a browser update coincidence or another factor.

    This report was made by an LLM. The analysis may be wrong, but is intended as a starting point for exploring the issue.

  5. added
    triage: needs reproduction
    on Jun 8, 2026
  6. matthewp commented on Jun 8, 2026

    @matthewp
    Contributor

    Please provide a reproduction, thanks.

  7. sam-fakhreddine commented on Jun 8, 2026

    @sam-fakhreddine
    Author

    Please provide a reproduction, thanks.

    #16992 (comment) you can see at this momment

  8. removed
    triage: needs reproduction
    on Jun 11, 2026
  9. added
    triage: needs triage
    and removed
    triage: needs triage
    on Jun 26, 2026
  10. matthewp commented on Jul 1, 2026

    @matthewp
    Contributor

    @astrobot-houston triage — previous run could not reproduce. Please try again with the reporter's exact reproduction steps.

  11. added
    triage: needs triage
    and removed
    triage: needs triage
    on Jul 1, 2026
  12. matthewp commented on Jul 1, 2026

    @matthewp
    Contributor

    @sam-fakhreddine are you still having this problem? I think #16997 might have fixed it.

  13. self-assigned this
    on Jul 1, 2026
  14. added
    triage: unable to reproduce
    and removed
    triage: needs triage
    on Jul 1, 2026
  15. itsmiketorres commented on Jul 2, 2026

    @itsmiketorres

    FWIW: got some "help" on this one. Some projects discourage LLM assistance but I think this might be useful to someone. Two outputs both identify swap-functions.ts as the root cause.

    Scanned the repo: found the bug surface in packages/astro/src/transitions/swap-functions.ts → swapBodyElement().
    
    Root-caused the regression: between 6.4.2 and 6.4.4, persist elements were lifted to <html> via Node.prototype.moveBefore() for zero-detachment. Chromium's moveBefore throws a DOMException for subtrees containing a native Popover API element (state-preserving-disqualified). The unguarded throw aborted the entire swapBodyElement, leaving the persisted node out of the final DOM.
    
    Fixed it by wrapping every moveBefore call in try/catch with a safe fallback chain: moveBefore → appendChild/replaceWith → leave-in-place+let replaceWith() orphan and reattach. No thrown exception escapes the function now.
    

    Separate "scan"

    What was happening
    
    The regression lives in packages/astro/src/transitions/swap-functions.ts → swapBodyElement(), the <ClientRouter /> body-swap routine.
    
    To keep persisted <canvas> elements from losing their WebGL context, the swap was optimized to relocate transition:persist elements using the state-preserving atomic move Node.prototype.moveBefore() (Chrome 133+). The problem: moveBefore() is specified to throw for subtrees it can't move while preserving state — and native popover elements are exactly such a case. The old code called moveBefore() unguarded, so the exception escaped swapBodyElement() → swap() → the startViewTransition update callback, where the router only logs the error. The swap aborted mid-flight, the new body was never installed, and the persisted <header> vanished.
    
    This also explains the "intermittent" feel: only browsers that implement moveBefore() were affected; Safari/older browsers used the classic path and were fine — which is why reverting past the optimization appeared to fix it.
    
    The fix
    
    A small moveNode() helper that prefers moveBefore() but falls back to a classic insertBefore() move whenever moveBefore() is missing or throws. The canvas/WebGL optimization is preserved wherever it works; popovers (and older browsers) safely take the classic path, matching pre-regression behavior. The fallback keeps the node connected (html → new body), so there's no detachment flash.
    
  16. added
    triage: needs triage
    and removed
    triage: needs triage
    on Jul 2, 2026
  17. astrobot-houston commented on Jul 2, 2026

    @astrobot-houston
    Contributor
    • Reproduced: No — the bug is specific to Cloudflare Workers (workerd runtime) and the offending change has already been reverted on main.
    • Exploration: Partial — View branch
    • Unit Test: No — unable to reproduce; the fix (Revert isNode workerd detection that caused Cloudflare build regression #16997) is already merged.
    • Priority: P3: minor bug. This affected a specific combination of transition:persist + native popover elements on Cloudflare Workers only, and was caused by a since-reverted change. It is already fixed on main.

    This issue was caused by PR #16720, which changed the isNode detection in packages/astro/src/runtime/server/render/util.ts to return false inside Cloudflare Workers (workerd). This forced the rendering pipeline onto renderToReadableStream instead of renderToAsyncIterable, which appears to have mishandled data-astro-transition-persist attributes during streaming — causing persisted elements containing native popover attributes to disappear on navigation. The reporter's own analysis correctly identified this code path.

    This issue has already been fixed. PR #16997 (commit dc45246) reverted the isNode workerd detection change, restoring previous behavior. Upgrading to a version of Astro that includes this revert should resolve the issue. As @matthewp suggested, please confirm whether upgrading fixes this for you.

    Note: The third-party analysis suggesting moveBefore() throws for popover elements was not confirmed in our testing — Chrome 150's moveBefore() successfully moves subtrees containing popover elements without throwing. The actual root cause was the server-side rendering path change on Cloudflare, not the client-side swap logic.

    Full Triage Report

    Triage Report: Issue #16992

    Issue Details

    Title: Regression (6.4.4): transition:persist fails to render elements containing native popover attributes

    URL: #16992

    Author: sam-fakhreddine

    Labels: needs triage, triage: unable to reproduce

    Created: 2026-06-07T23:36:39Z

    Description

    The reporter claims that after upgrading from astro@6.4.2 to astro@6.4.4, any component using transition:persist that contains native HTML popover elements completely fails to render/persist across page navigations. The entire persisted element instantly disappears from the DOM upon client-side navigation. Reverting to 6.4.2 immediately fixes the issue.

    The reporter uses @astrojs/cloudflare adapter with output: 'server'.

    Expected Result

    The persisted element should remain in the DOM across navigations, exactly as it does in Astro 6.4.2 and earlier.

    Reporter's Analysis

    The reporter identified the root cause as the change to isNode in packages/astro/src/runtime/server/render/util.ts (PR #16720), which explicitly opted Cloudflare Workers out of isNode. This caused Astro to switch from renderToAsyncIterable to renderToReadableStream on Cloudflare, which they believed was mishandling the data-astro-transition-persist attributes during streaming.

    Third-Party Analysis (from @itsmiketorres)

    A separate analysis (LLM-generated) suggested the root cause was in swap-functions.ts → swapBodyElement(), where moveBefore() would throw a DOMException for subtrees containing native popover elements ("state-preserving-disqualified"), causing the entire swap to abort.

    Reproduction Environment

    Reproduction Attempt

    Setup

    Created a reproduction in triage/gh-16992/ matching the reporter's exact reproduction repo structure:

    1. astro.config.mjs with output: 'server' (no Cloudflare adapter since we can't run workerd locally)
    2. src/pages/index.astro — Full HTML page with <ClientRouter />, a <header transition:persist="header-nav"> containing a native popover element with popovertarget button
    3. src/pages/about.astro — Same structure, different main content

    This matches the reporter's reproduction at https://github.com/sam-fakhreddine/astro-6.4.4-popover-persist-bug exactly, minus the @astrojs/cloudflare adapter.

    Tests Performed

    1. Basic navigation (popover closed): Navigated from Index → About by clicking the link. The header with popover elements persisted correctly. The heading changed from "Index Page" to "About Page" while the persistent header remained.

    2. Navigation with popover open: Opened the popover by clicking "Open Popover", then navigated to About page. The header persisted correctly — the popover closed during navigation (expected for popover="auto"), but the header itself remained in the DOM.

    3. moveBefore() behavior with popovers: Directly tested whether document.documentElement.moveBefore(header, null) throws when the header contains popover elements — it does NOT throw in Chrome 150 (both with popover closed and open).

    4. Baseline verification: The test setup is valid — pages load correctly, ClientRouter works, navigation occurs via client-side routing.

    Key Finding: #16997 Already Fixes This

    The most likely fix has already been merged. PR #16997 (commit dc45246) reverted PR #16720, which was the isNode workerd detection change that the reporter identified as the cause. This revert is already in our current codebase.

    The reporter's analysis was correct: the issue was that isNode returned false on Cloudflare Workers after #16720, causing Astro to use renderToReadableStream instead of renderToAsyncIterable. This change was reverted in #16997 due to a separate Cloudflare build regression report.

    Maintainer @matthewp also suggested in the issue comments that #16997 might have fixed this issue.

    Why We Can't Reproduce

    1. The fix (Revert isNode workerd detection that caused Cloudflare build regression #16997) is already merged — Our codebase no longer contains the offending change.
    2. We can't run Cloudflare Workers locally — The reporter uses @astrojs/cloudflare adapter, and the bug is specific to the workerd runtime where isNode was affected.
    3. moveBefore() doesn't throw for popovers in Chrome 150 — The third-party analysis about moveBefore() throwing for popover elements was not confirmed in our testing. This may be version-specific or the analysis may be incorrect.

    Result

    Not reproduced — but the fix (#16997) is already merged. The bug was likely real and specific to Cloudflare Workers where the isNode change (#16720) caused a different rendering path. This is effectively a host-specific issue that has already been resolved.

    Recommendation

    This issue can likely be closed, pending confirmation from the reporter that upgrading past the version containing #16997 resolves their issue. @matthewp already asked the reporter for this confirmation.

    This report was made by an LLM. The analysis may be wrong, but is intended as a starting point for exploring the issue.

  18. added
    triage: skipped
    and removed
    triage: needs triage
    on Jul 2, 2026
  19. matthewp commented on Jul 7, 2026

    @matthewp
    Contributor

    Closing since we haven't been able to reproduce on latest. Please feel free to open a new issue if you are still having the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

triage: skippedtriage: unable to reproduce

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions