Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nette/tracy
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 77992970790b0eaadb1e2640cff60982a6dae297
Choose a base ref
..
head repository: nette/tracy
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a386d3810439f4a72950ed96983b890409c32660
Choose a head ref
Showing with 40 additions and 33 deletions.
  1. +3 −3 src/Tracy/Bar/assets/bar.js
  2. +1 −1 src/Tracy/BlueScreen/assets/bluescreen.js
  3. +2 −10 src/Tracy/Dumper/Renderer.php
  4. +20 −19 src/Tracy/Dumper/assets/dumper.js
  5. +14 −0 tests/Tracy/Dumper.toHtml().lazy.auto.phpt
6 changes: 3 additions & 3 deletions src/Tracy/Bar/assets/bar.js
Original file line number Diff line number Diff line change
@@ -412,10 +412,10 @@ class Debug
let panel = Debug.panels[tab.rel];
if (panel.is(Panel.PEEK)) {
delete Debug.panels[tab.rel];
panel.elem.parentNode.removeChild(panel.elem);
panel.elem.remove();
}
});
row.parentNode.removeChild(row);
row.remove();
});

if (rows[0]) { // update content in first-row panels
@@ -508,7 +508,7 @@ class Debug

static loadScript(url) {
if (Debug.scriptElem) {
Debug.scriptElem.parentNode.removeChild(Debug.scriptElem);
Debug.scriptElem.remove();
}
Debug.scriptElem = document.createElement('script');
Debug.scriptElem.src = url;
2 changes: 1 addition & 1 deletion src/Tracy/BlueScreen/assets/bluescreen.js
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class BlueScreen
static loadAjax(content) {
let ajaxBs = document.getElementById('tracy-bs');
if (ajaxBs) {
ajaxBs.parentNode.removeChild(ajaxBs);
ajaxBs.remove();
}
document.body.insertAdjacentHTML('beforeend', content);
ajaxBs = document.getElementById('tracy-bs');
12 changes: 2 additions & 10 deletions src/Tracy/Dumper/Renderer.php
Original file line number Diff line number Diff line change
@@ -47,9 +47,6 @@ final class Renderer
/** @var Value[]|null */
private $snapshotSelection;

/** @var array */
private $snapshotParents = [];

/** @var array */
private $parents = [];

@@ -441,14 +438,9 @@ private function copySnapshot($value): void
$this->copySnapshot($v);
}
} elseif ($value instanceof Value && $value->type === Value::TYPE_REF) {
if (isset($this->snapshotSelection[$value->value])) {
return;
}
$ref = $this->snapshotSelection[$value->value] = $this->snapshot[$value->value];
if (!isset($this->snapshotParents[$value->value])) {
$this->snapshotParents[$value->value] = true;
if (!isset($this->snapshotSelection[$value->value])) {
$ref = $this->snapshotSelection[$value->value] = $this->snapshot[$value->value];
$this->copySnapshot($ref);
unset($this->snapshotParents[$value->value]);
}
} elseif ($value instanceof Value && $value->items) {
foreach ($value->items as [, $v]) {
39 changes: 20 additions & 19 deletions src/Tracy/Dumper/assets/dumper.js
Original file line number Diff line number Diff line change
@@ -19,25 +19,26 @@ class Dumper
{
static init(context) {
// full lazy
(context || document).querySelectorAll('[data-tracy-snapshot][data-tracy-dump]').forEach((el) => { // <pre>
let snapshot = JSON.parse(el.getAttribute('data-tracy-snapshot'));
el.removeAttribute('data-tracy-snapshot');
el.appendChild(build(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el.classList.contains('tracy-collapsed')));
el.removeAttribute('data-tracy-dump');
el.classList.remove('tracy-collapsed');
(context || document).querySelectorAll('[data-tracy-snapshot][data-tracy-dump]').forEach((pre) => { // <pre>
let snapshot = JSON.parse(pre.getAttribute('data-tracy-snapshot'));
pre.removeAttribute('data-tracy-snapshot');
pre.appendChild(build(JSON.parse(pre.getAttribute('data-tracy-dump')), snapshot, pre.classList.contains('tracy-collapsed')));
pre.removeAttribute('data-tracy-dump');
pre.classList.remove('tracy-collapsed');
});

// snapshots
(context || document).querySelectorAll('meta[itemprop=tracy-snapshot]').forEach((el) => {
let snapshot = JSON.parse(el.getAttribute('content'));
el.parentElement.querySelectorAll('[data-tracy-dump]').forEach((el) => { // <pre>
if (el.closest('[data-tracy-snapshot]')) { // ignore unrelated <span data-tracy-dump>
(context || document).querySelectorAll('meta[itemprop=tracy-snapshot]').forEach((meta) => {
let snapshot = JSON.parse(meta.getAttribute('content'));
meta.parentElement.querySelectorAll('[data-tracy-dump]').forEach((pre) => { // <pre>
if (pre.closest('[data-tracy-snapshot]')) { // ignore unrelated <span data-tracy-dump>
return;
}
el.appendChild(build(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el.classList.contains('tracy-collapsed')));
el.removeAttribute('data-tracy-dump');
el.classList.remove('tracy-collapsed');
pre.appendChild(build(JSON.parse(pre.getAttribute('data-tracy-dump')), snapshot, pre.classList.contains('tracy-collapsed')));
pre.removeAttribute('data-tracy-dump');
pre.classList.remove('tracy-collapsed');
});
meta.remove();
});

if (Dumper.inited) {
@@ -56,13 +57,13 @@ class Dumper
// initializes lazy <span data-tracy-dump> inside <pre data-tracy-snapshot>
if ((el = e.target.closest('[data-tracy-snapshot]'))) {
let snapshot = JSON.parse(el.getAttribute('data-tracy-snapshot'));
el.removeAttribute('data-tracy-snapshot');
el.querySelectorAll('[data-tracy-dump]').forEach((el) => {
if (!el.nextSibling) {
el.after(document.createTextNode('\n')); // enforce \n after toggler
el.removeAttribute('data-tracy-snapshot');
el.querySelectorAll('[data-tracy-dump]').forEach((toggler) => {
if (!toggler.nextSibling) {
toggler.after(document.createTextNode('\n')); // enforce \n after toggler
}
el.nextSibling.after(buildStruct(JSON.parse(el.getAttribute('data-tracy-dump')), snapshot, el, true, []));
el.removeAttribute('data-tracy-dump');
toggler.nextSibling.after(buildStruct(JSON.parse(toggler.getAttribute('data-tracy-dump')), snapshot, toggler, true, []));
toggler.removeAttribute('data-tracy-dump');
});
}
});
14 changes: 14 additions & 0 deletions tests/Tracy/Dumper.toHtml().lazy.auto.phpt
Original file line number Diff line number Diff line change
@@ -64,6 +64,20 @@ Assert::match(<<<'XX'
XX
, Dumper::toHtml($obj));

// recursion fix
$arr = [new stdClass, 'arr' => [1, 2, 3, 4, 5, 6]];
$obj = (object) $arr;
$obj->arr[] = $obj;

Assert::match(<<<'XX'
<pre class="tracy-dump tracy-light" data-tracy-snapshot='{"%d%":{"object":"stdClass","items":[["0",{"ref":%d%},3],["arr",[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,{"ref":%d%}]],3]]},"%d%":{"object":"stdClass","items":[]}}'
><span class="tracy-toggle"><span class="tracy-dump-object">stdClass</span> <span class="tracy-dump-hash">#%d%</span></span>
<div><span class="tracy-dump-indent"> </span><span class="tracy-dump-dynamic">0</span>: <span class="tracy-dump-object">stdClass</span> <span class="tracy-dump-hash">#%d%</span>
<span class="tracy-dump-indent"> </span><span class="tracy-dump-dynamic">arr</span>: <span class="tracy-toggle tracy-collapsed" data-tracy-dump='[[0,1],[1,2],[2,3],[3,4],[4,5],[5,6],[6,{"ref":%d%}]]'><span class="tracy-dump-array">array</span> (7)</span>
</div></pre>
XX
, Dumper::toHtml($obj));


// lazy dump & max items
$arr = [1, 2, 3, 4, 5, 6, 7, 8];