Skip to content

Commit

Permalink
Fix: prevent island re-rendering when using transition:persist (#11854)…
Browse files Browse the repository at this point in the history
  • Loading branch information
azhirov authored Sep 17, 2024
1 parent 00ea675 commit 0b59fe7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 0b59fe7

Please sign in to comment.