Skip to content

Commit

Permalink
Fix: prevent island re-rendering when using transition:persist (witha…
Browse files Browse the repository at this point in the history
  • Loading branch information
azhirov committed Sep 3, 2024
1 parent 5d7bc70 commit 1107784
Show file tree
Hide file tree
Showing 2 changed files with 10 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)
6 changes: 5 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,7 @@ 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 +133,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 1107784

Please sign in to comment.