Skip to content

fix: initialize standalone toolbar#9950

Open
michalsn wants to merge 2 commits intocodeigniter4:developfrom
michalsn:fix/toolbar
Open

fix: initialize standalone toolbar#9950
michalsn wants to merge 2 commits intocodeigniter4:developfrom
michalsn:fix/toolbar

Conversation

@michalsn
Copy link
Member

Description
This PR fixes a bug where the Debug Toolbar loaded from ?debugbar_time=... (via Debugbar-Link headers for AJAX/non-HTML responses) appeared but was not interactive.

The fix adds a dedicated standalone bootstrap script for this mode, while keeping toolbar.js focused on core toolbar behavior. It also provides a loadDoc() fallback only when the main loader flow is absent, so the History section keeps working on standalone toolbar pages.

Fixes #9949

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value (without duplication)
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

init: function () {
this.toolbarContainer = document.getElementById("toolbarContainer");
// Standalone debugbar pages do not have #toolbarContainer, use body as fallback.
this.toolbarContainer = document.getElementById("toolbarContainer") || document.body;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ciDebugBar.init() assumes that #toolbarContainer exists for both JavaScript and CSS theme handling, but on standalone debugbar pages (?debugbar_time=...) this element is missing. Falling back to document.body avoids errors, however without assigning the expected ID the existing CSS no longer matches, so the theme toggle appears non-functional.

Suggested change
this.toolbarContainer = document.getElementById("toolbarContainer") || document.body;
this.toolbarContainer = document.getElementById("toolbarContainer");
if (!this.toolbarContainer) {
this.toolbarContainer = document.body;
if (!document.body.id) {
document.body.id = "toolbarContainer";
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right about the theme toggler - I'll fix that. But I'll keep standalone bootstrapping in a separate file to preserve clear responsibility boundaries.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate you taking the time to explain your reasoning.

Copy link
Contributor

@datamweb datamweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
In general, many of the existing issues in the debugging tools seem to stem from insufficient test coverage as well, which might be worth addressing over time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Standalone Debugbar is not properly initialized

2 participants