Skip to content

Commit

Permalink
feat: update LivewireCollector to supports Livewire v3 (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
akunbeben authored Jul 26, 2023
1 parent cf4554d commit 56a2dc1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/DataCollector/LivewireCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Support\Fluent;
use Illuminate\Support\Str;
use Livewire\Livewire;
use Livewire\Component;

/**
* Collector for Models.
Expand Down Expand Up @@ -46,6 +47,26 @@ public function __construct(Request $request)

$this->data[$key] = $this->formatVar($data);
});

Livewire::listen('render', function (Component $component) use ($request) {
// Create an unique name for each compoent
$key = $component->getName() . ' #' . $component->getId();

$data = [
'data' => $component->all(),
];

if ($request->request->get('id') == $component->getId()) {
$data['oldData'] = $request->request->get('data');
$data['actionQueue'] = $request->request->get('actionQueue');
}

$data['name'] = $component->getName();
$data['component'] = get_class($component);
$data['id'] = $component->getId();

$this->data[$key] = $this->formatVar($data);
});
}

public function collect()
Expand Down
2 changes: 1 addition & 1 deletion src/LaravelDebugbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ protected function isDebugbarRequest()
protected function isJsonRequest(Request $request)
{
// If XmlHttpRequest or Live, return true
if ($request->isXmlHttpRequest() || $request->headers->get('X-Livewire')) {
if ($request->isXmlHttpRequest() || $request->headers->has('X-Livewire')) {
return true;
}

Expand Down

0 comments on commit 56a2dc1

Please sign in to comment.