Skip to content

Commit b625b57

Browse files
committed
Use content hash as comment key
1 parent 2c86c2a commit b625b57

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

resources/views/comment-list.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class="w-8 h-8 text-gray-400 dark:text-gray-500"
1616

1717
@foreach ($this->comments as $comment)
1818
<livewire:commentions::comment
19-
:key="'comment-' . $comment->getId()"
19+
:key="$comment->getContentHash()"
2020
:comment="$comment"
2121
:mentionables="$mentionables"
2222
/>

src/Comment.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,14 @@ public function getLabel(): ?string
173173
return null;
174174
}
175175

176+
public function getContentHash(): string
177+
{
178+
return md5(json_encode([
179+
'body' => $this->body,
180+
'reactions' => $this->reactions->pluck('id'),
181+
]));
182+
}
183+
176184
protected static function newFactory()
177185
{
178186
return CommentFactory::new();

src/Contracts/RenderableComment.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ public function getCreatedAt(): \DateTime|\Carbon\Carbon;
2121
public function getUpdatedAt(): \DateTime|\Carbon\Carbon;
2222

2323
public function getLabel(): ?string;
24+
25+
public function getContentHash(): string;
2426
}

src/RenderableComment.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ public function getLabel(): ?string
9494
return $this->label;
9595
}
9696

97+
public function getContentHash(): string
98+
{
99+
return "comment-$this->id";
100+
}
101+
97102
public function toLivewire()
98103
{
99104
return [

0 commit comments

Comments
 (0)