Skip to content

Livewire “Snapshot missing” error when using getContentHash() as :key in comment loop #72

@CodeFlow110101

Description

@CodeFlow110101

Description:

When using the default comment-list.blade.php view, the Livewire component key is set to $comment->getContentHash(). This causes “Snapshot missing on Livewire component” errors if a comment with the same content is submitted or when the comment content changes.

Steps to Reproduce:

Publish the Commentions views.

Keep :key="$comment->getContentHash()" in the @foreach loop rendering comments.

Submit a comment identical to an existing comment.

Livewire throws: Snapshot missing on Livewire component with id:

Expected Behavior:

Livewire should correctly track each comment component without snapshot errors.

Workaround / Fix:
Replacing

:key="$comment->getContentHash()"

with

:key="$comment->getId()"

in the @foreach loop fixes the snapshot issue. This ensures a stable key for each comment component.

Final code:

@foreach ($this->comments as $comment)
    <livewire:commentions::comment
        :key="$comment->getId()"
        :comment="$comment"
        :mentionables="$mentionables" />
@endforeach

Versions:

Filament: ^4.0

Filament Commentions: ^0.7.4

Livewire: ^3.6

Laravel: ^12.0

PHP: 8.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions