Skip to content

Commit 9b1cabd

Browse files
authored
Merge pull request #1 from LokiExtensions/bug/async-localstorage-effect
infinite loop and page freeze caused by async Alpine.effect
2 parents ceeaee5 + 5f44c19 commit 9b1cabd

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

view/base/templates/script/store/message-store.phtml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ $fetchCookies = !(bool)$block->getSkipCookies();
2424
fetchCookies: <?= /* @noEscape */ $fetchLocalStorage ? 'true' : 'false' ?>,
2525
init() {
2626
if (this.fetchLocalStorage) {
27-
Alpine.effect(async () => {
27+
// Listen for LocalStorage initialization and load messages once
28+
document.addEventListener('loki:init:localstorage-store', async () => {
2829
const messageSection = await Alpine.store('LocalStorage').get('messages');
2930
if (messageSection && messageSection.messages) {
3031
this.messages = [...this.messages, ...messageSection.messages];
3132
this.reset();
3233
}
33-
});
34+
}, { once: true });
3435
}
3536
},
3637
getMessages() {
@@ -63,8 +64,8 @@ $fetchCookies = !(bool)$block->getSkipCookies();
6364
return !(message.type === type && message.text === text);
6465
});
6566
},
66-
saveMessage(type, text) {
67-
const messages = this.getMessagesFromStore();
67+
async saveMessage(type, text) {
68+
const messages = await this.getMessagesFromStore();
6869
messages.push({type, text});
6970
this.setMessageInStore(messages);
7071
},

0 commit comments

Comments
 (0)