mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
9ad8aefdd7
* client hydration scripts should be removed before navigation * chore: adding a changeset * also cleanup injected styles on page navigation
18 lines
652 B
JavaScript
18 lines
652 B
JavaScript
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();
|
|
}
|
|
});
|
|
|
|
// 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);
|
|
}
|
|
});
|