Skip to content

toast.js : Cannot read properties of null (reading 'classList') #37265

@lekoala

Description

@lekoala

Prerequisites

Describe the issue

I'm having the following issue in production on one website

Cannot read properties of null (reading 'classList')

At the lines

bootstrap/js/src/toast.js

Lines 114 to 116 in bf6240d

this._element.classList.add(CLASS_NAME_HIDE) // @deprecated
this._element.classList.remove(CLASS_NAME_SHOWING, CLASS_NAME_SHOW)
EventHandler.trigger(this._element, EVENT_HIDDEN)

My guess is that the element is already removed when that callback is called (i'm calling .dispose in the bs.hidden callback event I don't know if that's related or not. it should work without issues either way in my opinion).

Reduced test cases

My proposal is to simply add a null check before and return early if this._element is null

Demo
https://codepen.io/lekoalabe/pen/oNdPNXJ

click create modal
click create toast
accept sweet alert modal
try to click close icon on toast => it triggers the error

What operating system(s) are you seeing the problem on?

Windows

What browser(s) are you seeing the problem on?

Chrome

What version of Bootstrap are you using?

v5.2.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions