File tree Expand file tree Collapse file tree
view/base/templates/script/store Expand file tree Collapse file tree Original file line number Diff line number Diff 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 },
You can’t perform that action at this time.
0 commit comments