twbs / twbs/bootstrap

Bootstrap collapse close animation breaks when builiding in Angular's production mode

Open
#35,776 18 comments 4 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

I don't know if this can be treated as a bug of Bootstrap, it's just a specific usage of Javascript but I think it's worth to mention it here.

There is an issue with close animation of collapse panel when running Angular project with Bootstrap in production mode.
You can check it here: https://github.com/qbus00/angular-bootstrap-collapse-test

I have reported a bug to Angular-CLI team - https://github.com/angular/angular-cli/issues/22635 - but they have closed it describing it as "by design".

Quote from reply (can be also found under aforementioned link):

Hi, I investigated this morning and this seems to be caused by pure_getters terser option. Bootstrap relies on side effects example https://github.com/twbs/bootstrap/blob/a5483a8a96eaa88b4da7e432e0b925d0f3943dc3/js/src/collapse.js#L182 therefore in this case it is expected that the code breaks during runtime.
There are a couple of resolutions for this that you can read more about in https://github.com/angular/angular-cli/issues/11439#issuecomment-433141561
Closing as this is working as intended.

As I understand it's because Bootstrap's JS is using getters not only to access property but also modifies something, which when running minification breaks the functionality.

Is there something you can do about that? Maybe rewrite this portion of Javascript - instead of getters maybe just a simple function would fix this?

Mixture of Angular and Bootstrap is not something uncommon....

Reduced test cases
  1. Clone: https://github.com/qbus00/angular-bootstrap-collapse-test
  2. "npm install"
  3. "ng serve --configuration production"
  4. run browser
  5. click on CLICK ME button
  6. expand animation works
  7. click again CLICK ME button
  8. collapsing animation does not work
  9. stop ng serve
  10. repeat steps 3 to 9 but instead of "ng serve --configuration production" run "ng serve"
  11. collapsing animation now works (no optimization of bootstrap.js file)
What operating system(s) are you seeing the problem on?

Windows, macOS, Android, iOS, Linux

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

Chrome, Firefox, Microsoft Edge, Opera

What version of Bootstrap are you using?

5.1, 5.0

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

Reproduce the behavior with the linked angular-bootstrap-collapse-test project using “ng serve --configuration production,” then compare it with the unoptimized “ng serve” run. Read the referenced js/src/collapse.js location and the linked Angular CLI discussion to understand the minification interaction. Done means the collapse animation behaves consistently in the production build, with the approach verified against the reduced reproduction.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.