Skip to content

Bug: Crash in toggleViewsHints - getValidElementInner #9726

@mjomble

Description

@mjomble

PHP Version

8.3

CodeIgniter4 Version

4.6.3

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

I get this error in the browser console when using the debug toolbar to highlight views:

Uncaught TypeError: Cannot read properties of null (reading 'nodeName')
    at getValidElementInner (<anonymous>:320:45)
    at getValidElement (<anonymous>:356:25)
    at showHints (<anonymous>:373:36)
    at btn.parentNode.onclick (<anonymous>:513:17)

getValidElement calls getValidElementInner with nodeElement.previousElementSibling which is null when nodeElement is the comment node for "DEBUG-VIEW START 1 APPPATH/Views/bar.php"

As a result, the view highlighter gets stuck in an invalid state and further clicks on the button keep adding highlight elements and logging more errors.

Steps to Reproduce

app/Views/foo.php: <div><?= view('bar') ?></div>
app/Views/bar.php: <script></script>
any controller: return view('foo');

Render the view, then click on "Views" in the debug toolbar

Expected Output

No error

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions