Skip to content

Commit 52b029e

Browse files
committed
Add wrapper hack for turbo
1 parent 2394052 commit 52b029e

File tree

2 files changed

+42
-24
lines changed

2 files changed

+42
-24
lines changed

resources/js/turbolinks.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import * as Turbo from '@hotwired/turbo'
2+
import { PageRenderer } from '@hotwired/turbo'
23

34
import TurbolinksAdapter from 'vue-turbolinks'
45
Vue.use(TurbolinksAdapter)
56

67
Turbo.setProgressBarDelay(5)
8+
9+
// Patch the internal Turbo renderer to use #turbo-wrapper as the root node instead of the body
10+
// This allows things placed in the body by scripts like GTM to persist
11+
Object.assign(PageRenderer.prototype, {
12+
assignNewBody() {
13+
const container = document.querySelector("#turbo-wrapper")
14+
const newContainer = this.newElement.querySelector("#turbo-wrapper")
15+
16+
if (container && newContainer) {
17+
container.replaceWith(newContainer)
18+
} else {
19+
document.body.replaceWith(this.newElement)
20+
}
21+
}
22+
})

resources/views/layouts/app.blade.php

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,32 @@
2626
@config('design/head/includes')
2727
</head>
2828
<body class="text-neutral antialiased">
29-
<div id="app" class="flex flex-col min-h-dvh">
30-
@includeWhen(!request()->is('checkout'), 'rapidez::layouts.partials.header')
31-
@includeWhen(request()->is('checkout'), 'rapidez::layouts.checkout.header')
32-
<main>
33-
@yield('content')
34-
</main>
35-
@includeWhen(!request()->is('checkout'), 'rapidez::layouts.partials.footer')
36-
@includeWhen(request()->is('checkout'), 'rapidez::layouts.checkout.footer')
37-
@stack('page_end')
38-
</div>
29+
<div id="turbo-wrapper" class="contents">
30+
<div id="app" class="flex flex-col min-h-dvh">
31+
@includeWhen(!request()->is('checkout'), 'rapidez::layouts.partials.header')
32+
@includeWhen(request()->is('checkout'), 'rapidez::layouts.checkout.header')
33+
<main>
34+
@yield('content')
35+
</main>
36+
@includeWhen(!request()->is('checkout'), 'rapidez::layouts.partials.footer')
37+
@includeWhen(request()->is('checkout'), 'rapidez::layouts.checkout.footer')
38+
@stack('page_end')
39+
</div>
3940

40-
<script>window.config = @json(config('frontend'));</script>
41-
@if (session('notifications'))
42-
<script async>
43-
document.addEventListener('vue:loaded', function() {
44-
@foreach (session('notifications') ?? [] as $notification)
45-
window.Notify('{{ $notification['message'] }}', '{{ $notification['type'] ?? 'success' }}')
46-
@endforeach
47-
});
48-
</script>
49-
@endif
50-
@stack('foot')
51-
<svg hidden class="hidden">
52-
@stack('bladeicons')
53-
</svg>
41+
<script>window.config = @json(config('frontend'));</script>
42+
@if (session('notifications'))
43+
<script async>
44+
document.addEventListener('vue:loaded', function() {
45+
@foreach (session('notifications') ?? [] as $notification)
46+
window.Notify('{{ $notification['message'] }}', '{{ $notification['type'] ?? 'success' }}')
47+
@endforeach
48+
});
49+
</script>
50+
@endif
51+
@stack('foot')
52+
<svg hidden class="hidden">
53+
@stack('bladeicons')
54+
</svg>
55+
</div>
5456
</body>
5557
</html>

0 commit comments

Comments
 (0)