Skip to content

Conversation

@benrogmans
Copy link
Contributor

Sometimes (when using VueJS for instance) dom elements can not be found by the debugbar because the elements are not ready yet. Results in JS errors like:

Uncaught TypeError: Cannot set property 'innerHTML' of null
    at XMLHttpRequest.<anonymous> (index.php?debugbar:77)

Coming from toolbarloader.js.php:

var h2 = document.querySelector('#ci-history > h2');
h2.innerHTML = 'History <small>You have new debug data.</small> <button onclick="loadDoc(' + debugbarTime + ')">Update</button>';

#ci-history > h2 was not ready yet. Problem can be solved by making sure the debugbar is loaded right before the closing body tag.

Checklist:

  • Securely signed commits
  • Conforms to style guide

@benrogmans
Copy link
Contributor Author

Because I am not 100% confident about what is happening in toolbarloader.js.php I have chosen a safer fix for #2621: simply check whether the H2 was found.

I do think this feature to alert the user for new data is a little hacky; I would suggest to remove the newXHR() function and not fiddle with window.XMLHttpRequest.

@lonnieezell
Copy link
Member

This works fine for me without any errors. Merging.

@lonnieezell lonnieezell merged commit 0d5e981 into codeigniter4:develop Feb 27, 2020
@benrogmans benrogmans deleted the debugbar-defer-script branch February 27, 2020 07:43
@mostafakhudair
Copy link
Contributor

how about auto load debug-bar scripts automatic on new xhr without adding update button
var h2 = document.querySelector('#ci-history > h2'); h2.innerHTML = 'History <small>You have new debug data.</small>'; var badge = document.querySelector('a[data-tab="ci-history"] > span > .badge'); badge.className += ' active'; loadDoc(' + debugbarTime + ');

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.

3 participants