Skip to content

Commit

Permalink
Force re-execution of Partytown's head snippet on view transitions (#…
Browse files Browse the repository at this point in the history
…9666)

* Remove the header script before a view transition takes place to force a reload on the next page

* Add changeset

* Save another char
  • Loading branch information
martrapp committed Jan 11, 2024
1 parent 8059a19 commit cdf8ce0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-suits-beam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@astrojs/partytown": patch
---

Fixes an issue where Partytown scripts didn't execute after view transition
4 changes: 4 additions & 0 deletions packages/integrations/partytown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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: {
Expand All @@ -32,6 +33,7 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati
debug: options?.config?.debug ?? command === 'dev',
};
partytownSnippetHtml = partytownSnippet(partytownConfig);
partytownSnippetHtml += SELF_DESTRUCT_ON_VIEW_TRANSITION;
injectScript('head-inline', partytownSnippetHtml);
},
'astro:server:setup': ({ server }) => {
Expand Down Expand Up @@ -60,4 +62,6 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati
},
},
};


}

0 comments on commit cdf8ce0

Please sign in to comment.