From c3093dda6b1c742ee291a95a977409c6cf3d22ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Sun, 26 Oct 2025 19:45:15 +0100 Subject: [PATCH] Refactor comments, fix template --- assets/controllers/comments_mercure_controller.js | 4 ++-- src/Twig/Components/Organisms/Comments.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/controllers/comments_mercure_controller.js b/assets/controllers/comments_mercure_controller.js index 1717b5e..cb03561 100644 --- a/assets/controllers/comments_mercure_controller.js +++ b/assets/controllers/comments_mercure_controller.js @@ -27,8 +27,8 @@ export default class extends Controller { this.es = new EventSource(url.toString()); this.es.onmessage = async (msg) => { this._showLoading(); - this.component.set('payloadJson', JSON.stringify(msg.data)); - await this.component.render(); // Live re-hydrates from your server/cache + this.component.set('payloadJson', msg.data); + await this.component.render(); }; } diff --git a/src/Twig/Components/Organisms/Comments.php b/src/Twig/Components/Organisms/Comments.php index e878916..a83eddd 100644 --- a/src/Twig/Components/Organisms/Comments.php +++ b/src/Twig/Components/Organisms/Comments.php @@ -60,7 +60,7 @@ final class Comments /** Expose a view model to the template; keeps all parsing server-side */ public function getPayload(): array { - $data = $this->payloadJson !== '' + $data = !empty($this->payloadJson) ? (json_decode($this->payloadJson, true) ?: []) : $this->redisCacheService->getCommentsPayload($this->current) ?? [ 'comments' => [],