Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: prevent island from re-rendering when using transition:persist #11915

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-bees-love.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fix: prevent island from re-rendering when using transition:persist (#11854)
10 changes: 9 additions & 1 deletion packages/astro/src/transitions/swap-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ export function swapBodyElement(newElement: Element, oldElement: Element) {
// from the old page so that state is preserved.
newEl.replaceWith(el);
// For islands, copy over the props to allow them to re-render
if (newEl.localName === 'astro-island' && shouldCopyProps(el as HTMLElement)) {
if (
newEl.localName === 'astro-island' &&
shouldCopyProps(el as HTMLElement) &&
!isSameProps(el, newEl)
) {
el.setAttribute('ssr', '');
el.setAttribute('props', newEl.getAttribute('props')!);
}
Expand Down Expand Up @@ -133,6 +137,10 @@ const shouldCopyProps = (el: HTMLElement): boolean => {
return persistProps == null || persistProps === 'false';
};

const isSameProps = (oldEl: Element, newEl: Element) => {
return oldEl.getAttribute('props') === newEl.getAttribute('props');
};

export const swapFunctions = {
deselectScripts,
swapRootAttributes,
Expand Down
Loading