Skip to content

Commit

Permalink
also cleanup injected styles on page navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony Sullivan committed May 3, 2022
1 parent eb65a88 commit d56eb4e
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions packages/integrations/turbolinks/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,17 @@ import Turbolinks from 'turbolinks';
export { Turbolinks };

// Before every page navigation, remove any previously added component hydration scripts
document.addEventListener("turbolinks:before-render", function() {
const scripts = document.querySelectorAll("script[data-astro-component-hydration]");
for(const script of scripts) {
script.remove();
}
})
document.addEventListener('turbolinks:before-render', function () {
const scripts = document.querySelectorAll('script[data-astro-component-hydration]');
for (const script of scripts) {
script.remove();
}
});

// After every page navigation, move the bundled styles into the body
document.addEventListener('turbolinks:render', function () {
const styles = document.querySelectorAll('link[href^="/assets/asset"][href$=".css"]');
for (const style of styles) {
document.body.append(style);
}
});

0 comments on commit d56eb4e

Please sign in to comment.