Skip to content

Commit 73718f4

Browse files
authored
fix: Toolbar when maxHistory is set to 0 (#9506)
* fix: debugbar when maxHistory is set to 0 * apply code suggestion - make use of the historyLoad variable
1 parent 6fbf601 commit 73718f4

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed

system/Debug/Toolbar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ protected function format(string $data, string $format = 'html'): string
512512
{
513513
$data = json_decode($data, true);
514514

515-
if ($this->config->maxHistory !== 0 && preg_match('/\d+\.\d{6}/s', (string) service('request')->getGet('debugbar_time'), $debugbarTime)) {
515+
if (preg_match('/\d+\.\d{6}/s', (string) service('request')->getGet('debugbar_time'), $debugbarTime)) {
516516
$history = new History();
517517
$history->setFiles(
518518
$debugbarTime[0],

system/Debug/Toolbar/Views/toolbar.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,25 @@ var ciDebugBar = {
2727
.getElementById("debug-icon-link")
2828
.addEventListener("click", ciDebugBar.toggleToolbar, true);
2929

30-
// Allows to highlight the row of the current history request
31-
var btn = this.toolbar.querySelector(
32-
'button[data-time="' + localStorage.getItem("debugbar-time") + '"]'
33-
);
34-
ciDebugBar.addClass(btn.parentNode.parentNode, "current");
35-
3630
historyLoad = this.toolbar.getElementsByClassName("ci-history-load");
3731

38-
for (var i = 0; i < historyLoad.length; i++) {
39-
historyLoad[i].addEventListener(
40-
"click",
41-
function () {
42-
loadDoc(this.getAttribute("data-time"));
43-
},
44-
true
32+
if (historyLoad.length) {
33+
// Allows highlighting the row of the current history request
34+
var btn = this.toolbar.querySelector(
35+
'button[data-time="' + localStorage.getItem("debugbar-time-new") + '"]'
4536
);
37+
ciDebugBar.addClass(btn.parentNode.parentNode, "current");
38+
39+
40+
for (var i = 0; i < historyLoad.length; i++) {
41+
historyLoad[i].addEventListener(
42+
"click",
43+
function () {
44+
loadDoc(this.getAttribute("data-time"));
45+
},
46+
true
47+
);
48+
}
4649
}
4750

4851
// Display the active Tab on page load
@@ -77,14 +80,14 @@ var ciDebugBar = {
7780
links[i].addEventListener("click", function() {
7881
ciDebugBar.toggleDataTable(datatable)
7982
}, true);
80-
83+
8184
} else if (toggleData === "childrows") {
8285

8386
let child = links[i].getAttribute("data-child");
8487
links[i].addEventListener("click", function() {
8588
ciDebugBar.toggleChildRows(child)
8689
}, true);
87-
90+
8891
} else {
8992
links[i].addEventListener("click", ciDebugBar.toggleRows, true);
9093
}
@@ -174,10 +177,10 @@ var ciDebugBar = {
174177
);
175178

176179
if (target.classList.contains("debug-bar-ndisplay")) {
177-
ciDebugBar.switchClass(target, "debug-bar-ndisplay", "debug-bar-dtableRow");
180+
ciDebugBar.switchClass(target, "debug-bar-ndisplay", "debug-bar-dtableRow");
178181
} else {
179182
ciDebugBar.switchClass(target, "debug-bar-dtableRow", "debug-bar-ndisplay");
180-
}
183+
}
181184
}
182185
},
183186

@@ -261,7 +264,7 @@ var ciDebugBar = {
261264
} else {
262265
ciDebugBar.switchClass(ciDebugBar.icon, "debug-bar-dinlineBlock", "debug-bar-ndisplay");
263266
ciDebugBar.switchClass(ciDebugBar.toolbar, "debug-bar-ndisplay", "debug-bar-dinlineBlock");
264-
}
267+
}
265268
},
266269

267270
toggleViewsHints: function () {

user_guide_src/source/changelogs/v4.6.1.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Bugs Fixed
3535
- **Database:** Fixed a bug in ``Postgre`` and ``SQLite3`` handlers where composite unique keys were not fully taken into account for ``upsert`` type of queries.
3636
- **Database:** Fixed a bug in the ``OCI8`` and ``SQLSRV`` drivers where ``getVersion()`` returned an empty string when the database connection was not yet established.
3737
- **Logger:** Fixed a bug where the ``{line}`` variable couldn't be used without specifying the ``{file}`` variable when logging the message.
38+
- **Toolbar:** Fixed a bug where setting ``maxHistory`` to ``0`` would produce a JavaScript error in the Debug Toolbar.
39+
- **Toolbar:** Fixed a bug where setting ``maxHistory`` to ``0`` prevented log files from being properly cleared.
3840

3941
See the repo's
4042
`CHANGELOG.md <https://github.com/codeigniter4/CodeIgniter4/blob/develop/CHANGELOG.md>`_

0 commit comments

Comments
 (0)