Repository navigation
Description
Astro Info
Astro v7.3.5
Vite v8.3.1
Node v26.5.0
System macOS (arm64)
Package Manager npm
Output static
Adapter none
Integrations none
If this issue only occurs in one browser, which browser is a problem?
Chrome (Firefox not tested)
Describe the Bug
Since 7.2.1 (#17603), reifyMediaElements() in packages/astro/src/transitions/swap-functions.ts rebuilds every <video> and <audio> after a swap with document.createElement() followed by setAttribute() for each attribute.
In Chrome stable, a muted attribute added with setAttribute() does not mute the element. Blink only applies it when the parser creates the element (html_media_element.cc, the AttributeModificationReason::kByParser check); the behaviour the current HTML spec describes (whatwg/html#12389) is behind the MediaElementMutedDefaultState runtime flag, which is still experimental. So after a ClientRouter navigation, video.hasAttribute('muted') is true but video.muted is false.
That turns into audible sound on any page that starts muted video from a script (a carousel, play on scroll): the click that triggered the navigation gives the page sticky activation, so Chrome allows the unmuted play(). The same markup on a full page load is muted.
Steps with the repro, in Chrome 153.0.8010.53 on macOS:
- Open
/videodirectly:muted attribute: true, video.muted: true. - Go to
/and click the link to/video:muted attribute: true, video.muted: false.
Adding this line after the attribute copy in reifyMediaElements() fixes it in the repro (step 2 then shows video.muted: true):
if (media.hasAttribute('muted')) (fresh as HTMLMediaElement).muted = true;Workaround in user land: set video.muted = true on astro:page-load for every video that should be muted.
What's the expected result?
A <video muted> is still muted after a ClientRouter navigation, as it is on a full page load, so a script calling play() on it stays silent.
Link to Minimal Reproducible Example
Participation
- I am willing to submit a pull request for this issue.
Activity
astro-factory commentedon Sep 28, 2026
Triage complete
triage: fix pendingpackages/astro/e2e/view-transitions.test.ts) using Playwright with Chromium instead<video muted>on every ClientRouter navigation in Chrome/Chromium — the dominant browser. Any site using muted autoplay video (carousels, play-on-scroll) will unexpectedly play audio after navigation.The root cause is in
reifyMediaElements()inpackages/astro/src/transitions/swap-functions.ts(line 230). When recreating media elements after a ClientRouter swap, all attributes are copied viasetAttribute(). In Chrome,setAttribute('muted', '')on adocument.createElement()-created element setsdefaultMuted = truebut does not sync themutedIDL property — Chrome only does that when the HTML parser creates the element. So after navigation,video.hasAttribute('muted')istruebutvideo.mutedisfalse.I found a potential fix for this issue. The fix adds one line after the attribute copy loop to explicitly set
fresh.muted = truewhen themutedattribute is present, mirroring what the HTML parser does on a full page load. Verified that both direct navigation and ClientRouter navigation now correctly reportvideo.muted: true.Try this fix
You can test this fix right now without waiting for a release:
# astro npm i https://pkg.pr.new/astro@83667bdIf this fixes your issue, please leave a comment letting us know (for example
"confirmed, this fixes it"). A pull request will then be opened to get it merged.
Full Triage Report
Issue Title
ClientRouter:
<video muted>loses its muted state after navigation in Chrome, so scriptplay()is audibleReproduction
Successfully reproduced using the provided reproduction repo against current
mainwith Chrome 154./video:muted attribute: true, video.muted: true✅/to/video:muted attribute: true, video.muted: false❌Root Cause
File:
packages/astro/src/transitions/swap-functions.tsFunction:
reifyMediaElements()(lines 225–235)Introduced by: PR #17603 (Astro 7.2.1), commit
722eed64creifyMediaElements()was added to fix #17601 (inert media fromDOMParser). It recreates each<video>/<audio>viadocument.createElement()and copies attributes withsetAttribute(). In Chrome,setAttribute('muted', '')on a script-created element setsdefaultMuted = truebut leavesvideo.muted = false. The HTML parser normally syncs both, but Chrome'sAttributeModificationReason::kByParsercheck in Blink means this only happens for parser-created elements. The spec-conformant behavior is behind an experimental flag (MediaElementMutedDefaultState, see whatwg/html#12389).Affected Code Path
DOMParserswapBodyElement()→reifyMediaElements()recreates media elementssetAttribute('muted', '')copies the attribute but not the IDL propertyplay()→ video plays with sound (page has sticky activation from the click)Fix
Added one line in
reifyMediaElements()after the attribute copy loop:Verification
video.muted: false❌video.muted: true✅Tests
packages/astro/e2e/view-transitions.test.ts— "reified<video muted>preserves the muted IDL property after navigation"packages/astro/e2e/fixtures/view-transitions/src/pages/video-muted.astroChangeset
.changeset/wet-times-doubt.md—astro: patchGit diff
This report was made by an LLM. The analysis may be wrong, and the potential fix might not work, but is intended as a starting point for exploring the issue.
matthewp commentedon Sep 28, 2026
Bot, I can confirm this fixes it.
astro-factory commentedon Sep 28, 2026
The fix has been verified! A pull request has been created: #18163
fix(transitions): preserve muted IDL property on reified media elemen…