Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

The timing of tab rendered (when CSS class active is added to tab pane) is not consistent. #4273

Closed
gfaceless opened this issue Aug 26, 2015 · 6 comments

Comments

@gfaceless
Copy link

Hi all,

In theory, if we scheduel a $timeout in tabScope.active $watcher, the function schedueled by $timeout should execute after a full $digest cycle, during that full cycle, CSS class should be added to tab pane. (because bootstrap.tabs uses ng-class, which shares the same full cycle)

but see this plunkr, the timing is inconsistent. what causes this? It is possibly a bug.

This matters because in our current work we need to calculate DOM dimensions when tab toggles,
but display:none prevent that calculating.

$timeout() 50ms fixes this, creating some helper directive forcing to add active CSS class in tabScope.active $watcher also fixes this.

@icfantv
Copy link
Contributor

icfantv commented Aug 26, 2015

Just to fully understand, when you add your 50ms to the timer, are you adding it to the timer in your plunker?

This smells like a race condition to me. I don't think it will change anything because I think they are the same, but if you want to watch an attribute, you use attrs.$observe.

What happens if you use an ng-if that looks for the class? Would that be sufficient?

@gfaceless
Copy link
Author

@icfantv yes, adding 50ms to the timer in my plunkr fixes this.

And using attrs.$observe totally fixes this! I don't know why.

@icfantv
Copy link
Contributor

icfantv commented Aug 26, 2015

So they ARE NOT the same. I'm still trying to wrap my head around why, and chatted with some people smarter than me. Essentially, $scope abstracts the $watch away from the DOM whereas attrs is tied directly to the DOM. I still think it's a race condition in that the $watch is firing too soon - BTW, i was able to reproduce this consistently via the plunker on my iPad.

Some light reading:
See this for a more in-depth discussion, and this link for a better (albeit old) one.

@gfaceless
Copy link
Author

@icfantv Sorry I rarely used $observe and misused it.
The problem still exists after using $observe.
Thanks for your references, and I'm glad that this problem could be reproduced.

@gfaceless
Copy link
Author

@icfantv could you please reopen this issue?

@wesleycho wesleycho modified the milestones: 1.0.0, 0.14.3 Oct 23, 2015
@wesleycho
Copy link
Contributor

Going to close this issue in favor of #4836 - the tab API is buggy, and we need to fix the source of all the issues with a fresh & 100% improved API.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants