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

Tab Indicator: computeContentClientRect breaks React render pooling #4255

Open
jamesmfriedman opened this issue Jan 17, 2019 · 1 comment
Open

Comments

@jamesmfriedman
Copy link
Contributor

I've filed similar issues like this before, just found another example.

Basically, using getBoundingClientRect to force a repaint breaks React (and I'm presuming other things) that use Async rendering.

My current workaround was to just not call the foundation and copy the code over. This works as expected with a RAF

activate(previousIndicatorClientRect: ClientRect) {
    // Early exit if no indicator is present to handle cases where an indicator
    // may be activated without a prior indicator state
    if (!previousIndicatorClientRect) {
      this.foundation.adapter_.addClass(
        MDCTabIndicatorFoundation.cssClasses.ACTIVE
      );
      return;
    }

    const currentClientRect = this.computeContentClientRect();
    const widthDelta =
      previousIndicatorClientRect.width / currentClientRect.width;
    const xPosition = previousIndicatorClientRect.left - currentClientRect.left;
    this.foundation.adapter_.addClass(
      MDCTabIndicatorFoundation.cssClasses.NO_TRANSITION
    );
    this.foundation.adapter_.setContentStyleProperty(
      'transform',
      `translateX(${xPosition}px) scaleX(${widthDelta})`
    );
    // THE FIX
    requestAnimationFrame(() => {
      this.foundation.adapter_.removeClass(
        MDCTabIndicatorFoundation.cssClasses.NO_TRANSITION
      );
      this.foundation.adapter_.addClass(
        MDCTabIndicatorFoundation.cssClasses.ACTIVE
      );
      this.foundation.adapter_.setContentStyleProperty('transform', '');
    });
  }
@kfranqueiro kfranqueiro changed the title computeContentClientRect breaks React render pooling Tab Indicator: computeContentClientRect breaks React render pooling Jan 17, 2019
@acdvorak
Copy link
Contributor

Drawer and Dialog had the same issue. Need to add rAF. Thanks James!

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

No branches or pull requests

2 participants