Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/StaticCaching/Cachers/FileCacher.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,12 @@ public function getCsrfTokenJs(): string
window.livewire_token = data.csrf
}

if (window.hasOwnProperty('livewireScriptConfig')) {
window.livewireScriptConfig.csrf = data.csrf
if (window.livewireScriptConfig) {
// Replaces token if Livewire is already available. Usually on fast networks.
window.livewireScriptConfig.csrf = data.csrf;
} else {
// Delays replacing the token until Livewire is initialized. Usually on slow networks.
document.addEventListener('livewire:init', () => window.livewireScriptConfig.csrf = data.csrf);
}

document.dispatchEvent(new CustomEvent('statamic:csrf.replaced', { detail: data }));
Expand Down