Skip to content

Commit

Permalink
Prevent Livewire from starting multiple times (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasterZydra authored Jun 12, 2024
1 parent 01502cb commit 3fb2991
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/wire-extender.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let livewireScript;
let componentAssets;
let currentScript = document.currentScript;
let livewireStarted = false;

function getUri(append = '')
{
Expand Down Expand Up @@ -34,6 +35,10 @@ function getEmbedUri()

function injectLivewire()
{
if (window.Livewire || livewireStarted) {
return;
}

const style = document.createElement('style');
style.innerHTML = '<!-- Livewire Styles --><style >[wire\\:loading][wire\\:loading], [wire\\:loading\\.delay][wire\\:loading\\.delay], [wire\\:loading\\.inline-block][wire\\:loading\\.inline-block], [wire\\:loading\\.inline][wire\\:loading\\.inline], [wire\\:loading\\.block][wire\\:loading\\.block], [wire\\:loading\\.flex][wire\\:loading\\.flex], [wire\\:loading\\.table][wire\\:loading\\.table], [wire\\:loading\\.grid][wire\\:loading\\.grid], [wire\\:loading\\.inline-flex][wire\\:loading\\.inline-flex] {display: none;}[wire\\:loading\\.delay\\.none][wire\\:loading\\.delay\\.none], [wire\\:loading\\.delay\\.shortest][wire\\:loading\\.delay\\.shortest], [wire\\:loading\\.delay\\.shorter][wire\\:loading\\.delay\\.shorter], [wire\\:loading\\.delay\\.short][wire\\:loading\\.delay\\.short], [wire\\:loading\\.delay\\.default][wire\\:loading\\.delay\\.default], [wire\\:loading\\.delay\\.long][wire\\:loading\\.delay\\.long], [wire\\:loading\\.delay\\.longer][wire\\:loading\\.delay\\.longer], [wire\\:loading\\.delay\\.longest][wire\\:loading\\.delay\\.longest] {display: none;}[wire\\:offline][wire\\:offline] {display: none;}[wire\\:dirty]:not(textarea):not(input):not(select) {display: none;}:root {--livewire-progress-bar-color: #2299dd;}[x-cloak] {display: none !important;}</style>';
document.head.appendChild(style);
Expand All @@ -46,12 +51,18 @@ function injectLivewire()
}

function waitForLivewireAndStart() {
if (livewireStarted) {
return;
}

if(window.Livewire) {
startLivewire();
}
livewireScript.onload = async function () {
await startLivewire();
}

livewireStarted = true;
}

async function startLivewire(assets)
Expand Down

0 comments on commit 3fb2991

Please sign in to comment.