Skip to content

Commit 3b1971d

Browse files
authored
Merge pull request #3 from james2doyle/bugfix/livewire-restart
2 parents d075221 + 1ef2138 commit 3b1971d

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,21 @@ export default class SwupLivewirePlugin extends Plugin {
4343
el.setAttribute('wire:initial-data', JSON.stringify(data));
4444
});
4545

46-
// Aleays restart Livewire
47-
window.Livewire.restart();
46+
// Always restart Livewire
47+
if (typeof window.Livewire.restart === 'function') {
48+
window.Livewire.restart();
49+
} else {
50+
// handle versions of Livewire that don't have the .restart() method
51+
window.Livewire.all().map((component) => {
52+
// not always defined - depends on the component
53+
if (typeof component.call === 'function') {
54+
return component.call('restart');
55+
}
56+
// alternative version to component.call('restart') in case that doesn't exist
57+
if (typeof component.$wire?.$refresh === 'function') {
58+
component.$wire.$refresh();
59+
}
60+
});
61+
}
4862
}
4963
}

0 commit comments

Comments
 (0)