Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mikefolsom's avatar

Uncaught Snapshot missing on Livewire component with id:

I am upgrading a project from Livewire 2 to Livewire 3, and it has introduced an error I cannot figure out how to solve.

A parent Livewire TaskGrid component contains many nested Livewire TaskCard components.

Here is a simplified version of task-grid.blade.php

<div>

  <h3>New Tasks</h3>

  @foreach ($newTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask"
      key="task-card-{{ $existingTask->id }}" />
  @endforeach

  <h3>In-Progress Tasks</h3>

  @foreach ($inProgressTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask"
      key="task-card-{{ $existingTask->id }}" />
  @endforeach

  <h3>Completed Tasks</h3>

  @foreach ($completedTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask"
      key="task-card-{{ $existingTask->id }}" />
  @endforeach

</div>

Each TaskCard component allows for updating the status of the task, and then it dispatches a taskUpdated event, which TaskGrid listens for and re-renders.

// TaskCard.php

    public function updateStatus($status)
    {
        $this->task->update([
            'status' => $status,
        ]);

        // ...

        $this->dispatch('taskUpdated');
    }

When TaskGrid re-renders (which it does), the edited TaskCard is removed from the page but it does not re-appear in the appropriate area. The browser console displays an error:

Uncaught Snapshot missing on Livewire component with id:xxx

Inspecting the DOM reveals that an empty DIV with wire:id ‘xxx’ appears where the component should be rendered on the page.

<div wire:id=“xxx”></div>

Any ideas?

0 likes
3 replies
LaryAI's avatar
Level 58

The error you're encountering, "Uncaught Snapshot missing on Livewire component with id:xxx," typically occurs when Livewire is unable to properly track the state of a component during a re-render. This can happen for a few reasons, especially when dealing with nested components and dynamic updates.

Here are a few steps to troubleshoot and resolve this issue:

  1. Ensure Unique Keys: Make sure that each TaskCard component has a unique key. It looks like you're already doing this with key="task-card-{{ $existingTask->id }}", which is good.

  2. Check Event Dispatching: Ensure that the taskUpdated event is being dispatched correctly and that the parent component (TaskGrid) is listening for this event properly.

  3. Use wire:key: Instead of using the key attribute, try using wire:key to ensure Livewire can track the components correctly.

  4. Update Livewire: Ensure you are using the latest version of Livewire 3, as there might be bug fixes related to this issue.

  5. Re-rendering Logic: Ensure that the logic for re-rendering the TaskGrid component is correct. You might need to explicitly refresh the component or the tasks list.

Here is an updated version of your task-grid.blade.php using wire:key:

<div>
  <h3>New Tasks</h3>
  @foreach ($newTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask" wire:key="task-card-{{ $existingTask->id }}" />
  @endforeach

  <h3>In-Progress Tasks</h3>
  @foreach ($inProgressTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask" wire:key="task-card-{{ $existingTask->id }}" />
  @endforeach

  <h3>Completed Tasks</h3>
  @foreach ($completedTasks as $existingTask)
    <livewire:tasks.task-card :task="$existingTask" wire:key="task-card-{{ $existingTask->id }}" />
  @endforeach
</div>

Additionally, ensure that your TaskGrid component is listening for the taskUpdated event and handling it correctly. Here is an example of how you might set this up:

// TaskGrid.php

use Livewire\Component;

class TaskGrid extends Component
{
    protected $listeners = ['taskUpdated' => 'render'];

    public function render()
    {
        $newTasks = Task::where('status', 'new')->get();
        $inProgressTasks = Task::where('status', 'in-progress')->get();
        $completedTasks = Task::where('status', 'completed')->get();

        return view('livewire.task-grid', [
            'newTasks' => $newTasks,
            'inProgressTasks' => $inProgressTasks,
            'completedTasks' => $completedTasks,
        ]);
    }
}

By ensuring that the wire:key attribute is used and that the taskUpdated event is properly handled, you should be able to resolve the "Snapshot missing" error and ensure that your components re-render correctly.

mikefolsom's avatar

Still no luck. The parent component is re-rendering, and all of the 'categorization' logic is in the render() method. (It is actually quite complex.) I have tried many different syntaxes for applying keys (key vs :key vs wire:key, double curly braces vs strings vs PHP expressions...) Nothing in the normal bag of tricks seems to solve the issue. ☹️

inovamedia's avatar

I've stumbled upon this a couple of times too. One of the harder things in livewire to solve huh. I don't have an exact solution for you. I do have a couple things you could try, maybe one of them clicks.

But let me first try to explain the last time it happened to me. I had a foreach loop, that rendered multiple tinymce text editors. My component blade had something like in it, one level down (makes sense). I used some javascript to initialize the text areas to tinymce's. Tiny mce replaces the textarea if I am correct, and adds children and stuff. I believe because of this, the same kind of error occurred to me.

I did add a wire:ignore attribute to the direct parent elements of the tinymce editors, and all of the sudden it worked.

So, try to find of out if some javascript is modifying your dom too. And try wire:ignore on the parent of the html that is being modified.

Another thing to check is to see if there are any html tags that have for example duplicate ids. 20 years ago when writing static html, we did that using w3c validators. Nowadays, your browser (I believe only firefox) can do that for you via the inspector. If you have such problems on your page, some icons will popup in the inspector, just left to the settings cog at the right side of the screen.

If that doesn't work too, check if you'd close all html tags properly. or wrap your components in an additional div inside that foreach loop. Or maybe wrap that foreach loop with a div.

Or try to strip your html as far as possible and maybe you'll find WHEN it happens. That's usually the step just before you discover WHY it happens.

Livewire can be a PITA, and I do think some of those errors, could be made easier to solve if someone puts some time into that.

Hopefully this helps a bit. If you do find a solution, please share.

Please or to participate in this conversation.