summaryrefslogtreecommitdiff
path: root/packages/integrations/turbolinks/client.js
blob: 2305f3cf48bf63a5622780db50f2909d09ffc39b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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);
	}
});