Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

fix(tabs): avoid width calculation deviations. #8293

Closed

Conversation

devversion
Copy link
Member

  • Currently when using centered tabs, the updateInkBarStyles method is getting executed infinitely (even without $$rAF, sync)
    This is impacting the performance significant, because we're calculating the styles on each function call.

The problem is, that the pagination wrapper uses another rounding process than the updateInkBarStyle method.
Now both calculations are using the same rounding process / logic and the width's are now correct.

Fixes #8289.

* Currently when using centered tabs, the `updateInkBarStyles` method is getting executed infinitely (even without $$rAF, sync)
 This is impacting the performance significant, because we're calculating the styles on each function call.

The problem is, that the pagination wrapper uses another rounding process than the `updateInkBarStyle` method.
Now both calculations are using the same rounding process / logic and the width's are now correct.

Fixes angular#8289.
@devversion devversion added the needs: review This PR is waiting on review from the team label May 1, 2016
}

function calcTabsWidth(tabs) {
var width = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@robertmesserle Not sure, why the width was initially at 1px?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIR, there was a specific reasoning for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not recall the reason at all, unfortunately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was to account for a wrapping bug regarding pagination where the last item was wrapping to a new line without it; however, this looks like a band-aid that was hastily thrown in rather than diagnosing the root cause.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll also note that this is added in response to issues with tabs living inside of dialogs, so you might try creating that sort of test case and see if any bugs show up.

@crisbeto
Copy link
Member

crisbeto commented May 1, 2016

Have you tried this in IE/Edge? Maybe it would help with #4940 as well.

@devversion
Copy link
Member Author

@crisbeto Thanks for the idea - but unfortunately it's not related to that issue, because this bug is only appearing when using md-center-tabs

@ThomasBurleson
Copy link
Contributor

@robertmesserle - can you review this please.

@robertmesserle
Copy link
Contributor

@ThomasBurleson @devversion LGTM, but I'd like to confirm with a demo of tabs inside of a dialog before merging - just to confirm that width = 1 is not necessary.

@ThomasBurleson
Copy link
Contributor

@devversion - can you create a codePen with a dialog that contains tabs ?

@devversion
Copy link
Member Author

devversion commented May 15, 2016

@ThomasBurleson Yeah, it works as expected

But unfortunately with localhost, since I have no possibility to host the PR changes anywhere.

topherfangio added a commit to profoundry-us/material that referenced this pull request May 18, 2016
Initially, the tabs used DOMSubtreeModified to listen for changes
and update the height, pagination and inkbar styles. At some point,
we used a different method to update the height, but we were still
watching all DOM changes and updating the pagination and inkbar
styles whenever the contents changed.

Fix this with the following two changes:

1. Move the DOM watching to a new md-tabs-dummy-wrapper directive
   which only watches for changes to the tab's labels (not the
   content too) so that the updates are called less frequently.

2. Replace DOMSubtreeModified watching with new MutationObservers
   which are more drastically more performant.

Additionally, some recent changes caused some bugs in the tabs by
using a cached version of the internal elements instead of calling
`getElements()` which searches the DOM and refreshes the cached
elements.

Fix by adding more calls to `getElements()` where appropriate to
properly update the cache after tabs may have changed.

Fixes angular#5681. References angular#4940, and might cause PR angular#8293 to need a
rebase if this goes in first.
ThomasBurleson pushed a commit that referenced this pull request May 19, 2016
Initially, the tabs used DOMSubtreeModified to listen for changes
and update the height, pagination and inkbar styles. At some point,
we used a different method to update the height, but we were still
watching all DOM changes and updating the pagination and inkbar
styles whenever the contents changed.

Fix this with the following two changes:

1. Move the DOM watching to a new md-tabs-dummy-wrapper directive
   which only watches for changes to the tab's labels (not the
   content too) so that the updates are called less frequently.

2. Replace DOMSubtreeModified watching with new MutationObservers
   which are more drastically more performant.

Additionally, some recent changes caused some bugs in the tabs by
using a cached version of the internal elements instead of calling
`getElements()` which searches the DOM and refreshes the cached
elements.

Fix by adding more calls to `getElements()` where appropriate to
properly update the cache after tabs may have changed.

Fixes #5681. References #4940, and might cause PR #8293 to need a
rebase if this goes in first.

Closes #8496
@devversion
Copy link
Member Author

devversion commented May 30, 2016

@topherfangio Can you take a look at this PR as well? (since you recently made some calculation changes)

@topherfangio
Copy link
Contributor

topherfangio commented May 31, 2016

@devversion Code looks good, but it seems this introduces a small issue in Safari.

In the "Dynamic Tabs" demo, if you add a new tab (I named mine "woot"), it does not properly scroll it into view. It seems to work fine in master on Safari, and it also works correctly in Chrome/Firefox with and without your PR, so I'm not sure why it's different in Safari.

If we can figure this out and get it fixed, I think it's good to go.

tabs-safari-issue

Note: The tab is indeed there and you can scroll it into view using the arrows; it just doesn't appear immediately.

@topherfangio
Copy link
Contributor

@ThomasBurleson Should be ready for review/merge.

I chatted with @devversion and realized my version of Safari is older and he can't reproduce the issue I mentioned above on the latest version, so I think it's good to go.

@devversion devversion deleted the fix/tabs-endless-ink-update branch June 3, 2016 16:48
@Splaktar Splaktar added pr: merge ready This PR is ready for a caretaker to review pr: lgtm This PR has been approved by the reviewer and removed needs: review This PR is waiting on review from the team labels Jul 19, 2018
@Splaktar Splaktar added this to the 1.1.0 milestone Jul 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: lgtm This PR has been approved by the reviewer pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants