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' => [],