Skip to content

Commit d56eb4e

Browse files
author
Tony Sullivan
committed
also cleanup injected styles on page navigation
1 parent eb65a88 commit d56eb4e

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

packages/integrations/turbolinks/client.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import Turbolinks from 'turbolinks';
22
export { Turbolinks };
33

44
// Before every page navigation, remove any previously added component hydration scripts
5-
document.addEventListener("turbolinks:before-render", function() {
6-
const scripts = document.querySelectorAll("script[data-astro-component-hydration]");
7-
for(const script of scripts) {
8-
script.remove();
9-
}
10-
})
5+
document.addEventListener('turbolinks:before-render', function () {
6+
const scripts = document.querySelectorAll('script[data-astro-component-hydration]');
7+
for (const script of scripts) {
8+
script.remove();
9+
}
10+
});
11+
12+
// After every page navigation, move the bundled styles into the body
13+
document.addEventListener('turbolinks:render', function () {
14+
const styles = document.querySelectorAll('link[href^="/assets/asset"][href$=".css"]');
15+
for (const style of styles) {
16+
document.body.append(style);
17+
}
18+
});

0 commit comments

Comments
 (0)