From 9c159238612e0d571edee9b03940ec8492ebdda9 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Wed, 15 May 2024 19:42:46 +0200 Subject: [PATCH 1/2] fix: recover IFrame of Partytown on View Transition --- packages/integrations/partytown/src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/integrations/partytown/src/index.ts b/packages/integrations/partytown/src/index.ts index 6930b13364f1..34c936d96a65 100644 --- a/packages/integrations/partytown/src/index.ts +++ b/packages/integrations/partytown/src/index.ts @@ -21,19 +21,19 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati let partytownSnippetHtml: string; const partytownEntrypoint = resolve('@builder.io/partytown/package.json'); const partytownLibDirectory = path.resolve(partytownEntrypoint, '../lib'); - const SELF_DESTRUCT_ON_VIEW_TRANSITION = `;((d,s)=>(s=d.currentScript,d.addEventListener('astro:before-swap',()=>s.remove(),{once:true})))(document);`; return { name: '@astrojs/partytown', hooks: { 'astro:config:setup': ({ config: _config, command, injectScript }) => { const lib = `${appendForwardSlash(_config.base)}~partytown/`; + const recreateIFrameScript = `;(e=>{e.addEventListener("astro:before-swap",e=>{let r=document.body.querySelector("iframe[src*='${lib}']");e.newDocument.body.append(r)})})(document);`; const partytownConfig = { lib, ...options?.config, debug: options?.config?.debug ?? command === 'dev', }; partytownSnippetHtml = partytownSnippet(partytownConfig); - partytownSnippetHtml += SELF_DESTRUCT_ON_VIEW_TRANSITION; + partytownSnippetHtml += recreateIFrameScript; injectScript('head-inline', partytownSnippetHtml); }, 'astro:server:setup': ({ server }) => { From 0dcec9c0d86314677610f376a55564a426f70546 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 17 May 2024 09:34:34 +0200 Subject: [PATCH 2/2] chore: add changeset entry --- .changeset/friendly-eagles-arrive.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .changeset/friendly-eagles-arrive.md diff --git a/.changeset/friendly-eagles-arrive.md b/.changeset/friendly-eagles-arrive.md new file mode 100644 index 000000000000..5e08a914a2a2 --- /dev/null +++ b/.changeset/friendly-eagles-arrive.md @@ -0,0 +1,9 @@ +--- +"@astrojs/partytown": patch +--- + +Prevent Partytown from crashing when View Transitions are enabled + +When View Transitions are turned on, Partytown executes on every transition. +It's not meant to be like that, and therefore it breaks the integration completely. +Starting from now, Partytown will be executed only once.