0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-24 22:46:02 -05:00

Three small improvements for handling client-only in view transitions (#8964)

* client-only fixes

* typo
This commit is contained in:
Martin Trapp 2023-10-31 20:16:03 +01:00 committed by GitHub
parent 35cd810f0f
commit ef8964c04d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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));
}
});
}