Skip to content

Conversation

@Arecsu
Copy link

@Arecsu Arecsu commented Nov 9, 2025

Changes

  • Fixes: Elements with declarative Shadow DOM in transition-persisted containers throw "Unable to re-attach to existing ShadowDOM" error during view transitions
  • The existing attachShadowRoots() function attempts to call attachShadow() on all elements with <template shadowrootmode>, but doesn't check if the element already has a shadow root from a previous page
  • This commonly occurs when using transition:persist on containers with web components that use declarative Shadow DOM (e.g., custom elements, third-party libraries)
  • The fix adds a simple check: if a shadow root already exists, skip re-attachment and just remove the template
  • Follow-up of a recent PR made by @delucis: Attach declarative Shadow DOM templates during view transition #14341

Testing

This happened when fixed hydration mismatches in number-flow/svelte, which is a wrapper around a web component that uses Declarative Shadow DOM. PR: barvian/number-flow#162

The component was inside a transition-persisted flyout in all page-routes.

  • Before: Navigation throws "Unable to re-attach to existing ShadowDOM" error
  • After: Navigation works smoothly, shadow roots preserved correctly

Docs

Not applicable — bug fix for existing view transitions feature.

Prevents 'Unable to re-attach to existing ShadowDOM' error when
transition-persisted elements contain declarative Shadow DOM.
@changeset-bot
Copy link

changeset-bot bot commented Nov 9, 2025

⚠️ No Changeset found

Latest commit: ac3a35a

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added the pkg: astro Related to the core `astro` package (scope) label Nov 9, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 9, 2025

CodSpeed Performance Report

Merging #14737 will not alter performance

Comparing Arecsu:main (ac3a35a) with main (91780cf)

Summary

✅ 6 untouched

@Arecsu
Copy link
Author

Arecsu commented Nov 9, 2025

If this needs to have a changeset, please let me know. I'm not sure I fully understood if this PR needs it 😅

Copy link
Member

@delucis delucis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good — thanks for the fix @Arecsu!

Yes, a changeset would be great here. This is a bug fix so it should be a patch to the astro package.

We have more guidance on how to write a changeset here: https://contribute.docs.astro.build/docs-for-code-changes/changesets/

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

Labels

pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants