twbs / twbs/bootstrap

Uncaught TypeError: Illegal invocation

Open
#38,373 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

js v5
Dominant language
MDX
Stars
175k
Forks
78.6k
Avg merge
7h 19m
Merged PRs (30d)
35

Description

Prerequisites
Describe the issue

After upgrade 3 to 5 bootstrap version and fully rework modals call, a get error "Uncaught TypeError: Illegal invocation".
Ashampoo_Snap_28 марта 2023 г 23h17m03s_014

I use react, and have everytime in DOM the element like (let's name it Container):
<div id="modalDlg"></div>.

First of all i initialize modal container by:
this.modalElement = new bootstrap.Modal($("#modalDlg"));

In Container i put conditionally by React some modal content like a:
<div className="modal-dialog"><div className="modal-content"><div className="modal-header"></div>Some content</div></div>

and after that try to show modal window like it is described in documentation for bootstrap v5:

this.modalElement.show()

But catch an error:
"Uncaught TypeError: Illegal invocation"

Help me please, spent already a lot of time for that (maybe you should handle errors with more description because it is really hard to debug such common errors)

Reduced test cases

https://codepen.io/diesel9/pen/QWVPmYR

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?

5.2.3

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced test case at https://codepen.io/diesel9/pen/QWVPmYR and compare its React modal initialization with the Bootstrap 5.2.3 modal documentation. Reproduce the Illegal invocation error in Chrome, then trace whether the issue is in the modal usage or Bootstrap's handling of the supplied element; done means the cause and a reproducible resolution are documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react
Domain
frontend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.