mirror of
https://github.com/withastro/astro.git
synced 2025-03-17 23:11:29 -05:00
https://github.com/withastro/astro/issues/11854
This commit is contained in:
parent
00ea675409
commit
0b59fe74d5
2 changed files with 14 additions and 1 deletions
5
.changeset/seven-bees-love.md
Normal file
5
.changeset/seven-bees-love.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix: prevent island from re-rendering when using transition:persist (#11854)
|
|
@ -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')!);
|
||||
}
|
||||
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue