mirror of
https://github.com/withastro/astro.git
synced 2025-03-31 23:31:30 -05:00
Force re-execution of Partytown's head snippet on view transitions (#9666)
* Remove the header script before a view transition takes place to force a reload on the next page * Add changeset * Save another char
This commit is contained in:
parent
8059a19ad3
commit
cdf8ce0627
2 changed files with 9 additions and 0 deletions
5
.changeset/afraid-suits-beam.md
Normal file
5
.changeset/afraid-suits-beam.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@astrojs/partytown": patch
|
||||
---
|
||||
|
||||
Fixes an issue where Partytown scripts didn't execute after view transition
|
|
@ -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: {
|
||||
|
@ -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 }) => {
|
||||
|
@ -60,4 +62,6 @@ export default function createPlugin(options?: PartytownOptions): AstroIntegrati
|
|||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue