fix(transitions): prevent WebGL context loss on persist canvas during Safari swap#15728
fix(transitions): prevent WebGL context loss on persist canvas during Safari swap#15728SvetimFM wants to merge 1 commit intowithastro:mainfrom
Conversation
… Safari swap Safari loses WebGL2 context when canvas elements are briefly detached from the DOM. swapBodyElement() previously called replaceWith() which detached all old body children (including transition:persist elements) before moving them to the new body. Fix: lift persist elements to <html> before the body swap so they stay in the DOM tree throughout the transition, then move them into the new body afterward. Fixes withastro#15727 Co-Authored-By: Claude Opus 4.6 <[email protected]>
🦋 Changeset detectedLatest commit: 4a14184 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Re: E2E test failure —
|
Summary
swapBodyElement()to lifttransition:persistelements to<html>before the bodyreplaceWith(), preventing Safari from losing WebGL2 context on<canvas>elements during page transitions.Details
Safari loses WebGL2 context when canvas elements are briefly detached from the DOM tree. The current
swapBodyElement()callsoldBody.replaceWith(newBody)first, which detaches the entire old body (including persist elements), then moves persist elements from old to new body. In the gap between detach and reattach, Safari fireswebglcontextlost.The fix moves persist elements to
<html>(a safe parent that survives the swap) beforereplaceWith(), then places them into the new body afterward. This means persist elements are never detached from the DOM, so Safari doesn't lose the WebGL context.Chrome and Firefox are unaffected by this change — they don't lose WebGL context on brief DOM detachment, so the fix is a no-op for them behaviorally.
Closes #15727 (Bug 3 — canvas context loss)
Test plan
<ClientRouter />+<canvas transition:persist>initializing WebGL2astro-islandpersist elements — props still copied correctly after swap🤖 Generated with Claude Code