fix(@astrojs/partytown): prevent crashes when View Transitions are enabled #11083
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes
This pull request intend to resolve the incompatibility of Partytown integration and View Transitions.
The Partytown snippet is supposed to be loaded only once, but when the View Transitions API gets activated, the <script> element containing this snippet is recreated on every transition. It has been changed and now it's executed only once.
Under certain conditions, Partytown may need an <iframe> element to be present on the page. When a view transition happens, this <iframe> is removed from the DOM. There has been a change added, which will move
<iframe>
element from the old document to the new one. The side-effect is all Partytown scripts will get re-executed. That behavior is aligned with other frameworks like Nuxt.Closes #11033
Testing
There is no testing suite present for Partytown. I believe we should work on implementing one, but that's probably out of scope for this pull request.
Docs
I'm not sure if docs update is needed, because Partytown never really worked with View Transitions 😅 On the other hand, it's worth mentioning that scripts will get re-executed on each transition.
/cc @withastro/maintainers-docs for feedback!