summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Martin Trapp <94928215+martrapp@users.noreply.github.com> 2023-10-31 20:16:03 +0100
committerGravatar GitHub <noreply@github.com> 2023-10-31 20:16:03 +0100
commitef8964c04d27688f14382363e01e19e85c3fec7f (patch)
treeb71d33de546e3e7da456f8e48337bd798e26f8dc
parent35cd810f0f988010fbb8e6d7ab205de5d816e2b2 (diff)
downloadastro-ef8964c04d27688f14382363e01e19e85c3fec7f.tar.gz
astro-ef8964c04d27688f14382363e01e19e85c3fec7f.tar.zst
astro-ef8964c04d27688f14382363e01e19e85c3fec7f.zip
Three small improvements for handling client-only in view transitions (#8964)
* client-only fixes * typo
-rw-r--r--packages/astro/src/transitions/router.ts12
1 files changed, 10 insertions, 2 deletions
diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts
index 583bf7dfa..b740326dd 100644
--- a/packages/astro/src/transitions/router.ts
+++ b/packages/astro/src/transitions/router.ts
@@ -532,9 +532,17 @@ async function prepareForClientOnlyComponents(newDocument: Document, toLocation:
if (newDocument.body.querySelector(`astro-island[client='only']`)) {
// Load the next page with an empty module loader cache
const nextPage = document.createElement('iframe');
- nextPage.setAttribute('src', toLocation.href);
+ // do not fetch the file from the server, but use the current newDocument
+ nextPage.srcdoc =
+ (newDocument.doctype ? '<!DOCTYPE html>' : '') + newDocument.documentElement.outerHTML;
nextPage.style.display = 'none';
document.body.append(nextPage);
+ // silence the iframe's console
+ // @ts-ignore
+ nextPage.contentWindow!.console = Object.keys(console).reduce((acc: any, key) => {
+ acc[key] = () => {};
+ return acc;
+ }, {});
await hydrationDone(nextPage);
const nextHead = nextPage.contentDocument?.head;
@@ -552,7 +560,7 @@ async function prepareForClientOnlyComponents(newDocument: Document, toLocation:
viteIds.forEach((id) => {
const style = document.head.querySelector(`style[${VITE_ID}="${id}"]`);
if (style && !newDocument.head.querySelector(`style[${VITE_ID}="${id}"]`)) {
- newDocument.head.appendChild(style);
+ newDocument.head.appendChild(style.cloneNode(true));
}
});
}