Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executing getBoundingClientRect() method raises performance delay in bootstrap 5.3.2 #39428

Open
3 tasks done
rajapandiyan-settu opened this issue Nov 22, 2023 · 1 comment · May be fixed by #39498
Open
3 tasks done

Comments

@rajapandiyan-settu
Copy link

rajapandiyan-settu commented Nov 22, 2023

Prerequisites

Describe the issue

Hi,

I am using Bootstrap 5.3.2 in my application.

Initially, I have a table, and I dynamically create and remove another table through a button click to calculate some values. For that, I have used the getBoundingClientRect() method.

This functionality worked fine in the previous version (4.6.2). However, with the 5.3.2 version, it is causing a performance delay.

<!-- working style sheet -->
    <link
      rel="stylesheet"
      href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
      integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N"
      crossorigin="anonymous"
    />
   <!-- issue style sheet -->
   <link
     href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css"
     rel="stylesheet"
     integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN"
     crossorigin="anonymous"
   />
   

Reduced test cases

Issue sample: https://stackblitz.com/edit/fvhzg3-9vnksx?file=index.html,index.js

Replication procedure:
Click the button and observe the console, which displays the time taken for the process.

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.3.2

@WOLFRIEND
Copy link

WOLFRIEND commented Dec 15, 2023

I've investigated this issue, and found that this performance problem is caused by this line of code

bootstrap/scss/_reboot.scss

Lines 506 to 508 in 4dcc376

+ * {
clear: left; // 2
}
:

legend {
  // Omitted piece of code...
  + * {
    clear: left; // 2
  }
  // Omitted piece of code...
}

This line was added as a fix in the following pull request: #30345. It fixes bug/behavior when leading elements after the legend are rendered in one line. Example link could be found in the following comment (after opening scroll it horizontally): #29712 (comment).
But, this bug/behavior is caused by the another pull request: #28917 where the following line of code has been added:

legend {
  float: left; // 1
  // Omitted piece of code...
}

It was added, because when we want to have a border on the fieldset element, it will be rendered not properly. Links with the example in the following comment:
#30345 (comment).

So let's recap. The main reason why all of this was added is the presence of a border on the fieldset element. But, the correct rendering of the border could be achieved with the outline property, instead of the border property.
Example link: https://stackblitz.com/edit/js-dydeas?file=index.html.

fieldset {
    border: none;
    outline: 3px solid #dee2e6;
  }

This approach works well for rendering a border around a fieldset element and also does not have the problem with the leading element next to the legend.

I've already created a pull request for it: #39498.
Since the method proposed above solves the problem of an incorrectly rendered border, I believe that we can safely remove unnecessary lines (which I suggested removing in my pull request). Because the problem described by @rajapandiyan-settu really greatly affects the performance.
Please review this issue and let me know if this proposal is suitable?

Related issues

P.S. @rajapandiyan-settu
Specific to your situation, you can download already minified bootstrap.min.css file into your project, so that you will use it not from CDN, but directly from your project, and delete unneccessary lines of code specified above.

P.S.2. @julien-deramond I've noticed that you reacted with the 👀 emoji, so maybe this investigation will be helpful for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging a pull request may close this issue.

3 participants