components icon indicating copy to clipboard operation
components copied to clipboard

Dialog does not support multiple tabs

Open starksds opened this issue 9 years ago • 37 comments

Bug, feature request, or proposal:

Bug: Multiple tabs in a dialog cause chrome to go aw snap

What is the expected behavior?

I should be able to have more than one tab in a dialog

What is the current behavior?

You can render one tab in a dialog but as soon as you add two chrome goes aw snap

What are the steps to reproduce?

Create a dialog. Have the contents of the dialog be tabs. Add one tab, everything works great. Add two or more tabs and chrome will eventually go aw snap.

What is the use-case or motivation for changing an existing behavior?

There is no purpose for using tabs if you can only have one

Which versions of Angular, Material, OS, browsers are affected?

Angular 2.2.4 Material 2.0.0-alpha.11-2

Is there anything else we should know?

No

starksds avatar Dec 09 '16 21:12 starksds

@starksds can you share reproduction code?

jelbourn avatar Dec 09 '16 21:12 jelbourn

@jelbourn I've already rolled back my changes. It works in alpha.9-3 if that helps you narrow down what might have changed.

starksds avatar Dec 09 '16 21:12 starksds

@crisbeto can you investigate this?

jelbourn avatar Dec 09 '16 22:12 jelbourn

I couldn't reproduce it by sticking the tab demos into a dialog. @starksds can you post your HTML?

crisbeto avatar Dec 10 '16 09:12 crisbeto

@crisbeto our app has a mix of bootstrap 4 and material 2 components since your components weren't finished when we started so that might be causing the issue.

Could you provide a plunker for your test case that I could try to implement in our app?

starksds avatar Dec 10 '16 12:12 starksds

@starksds I tried taking the various examples from here and putting them into the dialog demo here.

crisbeto avatar Dec 10 '16 16:12 crisbeto

I have the same issue without using dialog, I have many pages with tabs, but only two of them get stuck with 11-3 AS SOON AS I add more than one tab and all work fine with 10. Chrome tab gets stuck and consumes memory indefinitely until I kill the tab with task manager. I'll try to figure out how those two pages differ from the rest (the rest of pages was stuck as well after upgrade, which was caused by changing the selectedIndex variable, the solution was to change in setTimeout, but not for those two pages, where variable is not changed in code)

chpasha avatar Dec 11 '16 12:12 chpasha

I think I found a workaround and possibly a way to reproduce issue. I have a pure (without any code) component which is still stuck when having more than one tab. The only anomaly about this component is that it is in a lazily loaded module. As soon as I place the component in the entry module, everything works fine - so I thought something is not getting initialized when the component is lazily loaded. And then I placed the tab group in the div with *ngIf="isComponentLoaded" which is set to true only in ngAfterViewInit and guess what? It's working. If the variable is set in ngOnInit - the tab is stuck, there is something that is missing until component is fully initialized and after that it is safe to create the tabs, but not before that. I hope this information is enough to somehow reproduce the issue or make a guess about it's cause

chpasha avatar Dec 11 '16 13:12 chpasha

I still can't reproduce it @chpasha. I'm using a lazy-loaded module, but it still works fine. Here's what the entire setup looks like:

lazy.module.ts

import { NgModule } from '@angular/core';
import { MaterialModule } from '@angular/material';

import { LazyComponent }   from './lazy.component';
import { routing } from './lazy.routing';

@NgModule({
  imports: [routing, MaterialModule.forRoot()],
  declarations: [LazyComponent]
})
export class LazyModule {}

lazy.routing.ts

import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { LazyComponent } from './lazy.component';

const routes: Routes = [
  { path: '', component: LazyComponent }
];

export const routing: ModuleWithProviders = RouterModule.forChild(routes);

lazy.component.ts

import { Component } from '@angular/core';

@Component({
  template: `
    <md-tab-group md-dynamic-height>
      <md-tab>
        <template md-tab-label>Tab one</template>
        <!-- some lipsum goes here -->
      </md-tab>

      <md-tab>
        <template md-tab-label>Tab one</template>
        <!-- some lipsum goes here -->
      </md-tab>
    </md-tab-group>
  `
})
export class LazyComponent {}

Can you post what your HTML looks like?

crisbeto avatar Dec 11 '16 13:12 crisbeto

it is pure md-tab-group from documentation without anything, like <md-tab-group > <md-tab label="one"> </md-tab> <md-tab label="two"> </md-tab> </md-tab-group>

what part of you example makes the module lazy? this is lazy { path: "myurl", loadChildren: 'app/lazy.module#LazyModule' }

chpasha avatar Dec 11 '16 14:12 chpasha

It's the loadChildren parameter, instead of the usual component.

crisbeto avatar Dec 11 '16 14:12 crisbeto

you mean you do have loadChildren don't you?

chpasha avatar Dec 11 '16 14:12 chpasha

Yes, I forgot to paste in that part since it's in the main module, but it looks like this:

{path: 'lazy', loadChildren: 'lazy/lazy.module#LazyModule'}

crisbeto avatar Dec 11 '16 14:12 crisbeto

then there could be something else involved, I'm using angular-cli 1.0.0-beta.21 with webpack. Fact is - it was working just fine in the previous beta. It must be something in tab group that doesn't get loaded yet when the component is rendered since like I said, ngIf hack works, so the component is working just fine if created after the module and component are loaded. I will try to reproduce the issue with smallest possible setup

chpasha avatar Dec 11 '16 14:12 chpasha

P. S. the other components where tab group is working have following difference: the tab-group there is not declared directly in html layout but rather defined as standalone angular component (because of some business logic). So this still looks somehow like the matter of when the component is rendered (and besides that I see the Uncaught TypeError: Cannot read property 'elementRef' of undefined error for those components with a stacktrace ending at MdTabHeader._alignInkBarToSelectedTab).

chpasha avatar Dec 11 '16 14:12 chpasha

Ok, I got it. So, I have a component which shows md-progress-circle while route is loading.

@Component({
  selector: 'load-route-progress',
  templateUrl: './load-route-progress.component.html',
})
export class LoadRouteProgressComponent implements OnDestroy {

  private subscription: Subscription;
  public loading: Subject<boolean> = new Subject();

  public constructor(private router: Router) {
    this.subscription = router.events.subscribe(s => {
      if (s instanceof NavigationStart) {
        this.loading.next(true);
      }
      if (s instanceof NavigationEnd) {
        this.loading.next(false);
      }
    });
  }
  ngOnDestroy(): void {
    this.subscription.unsubscribe();
  }
}

it has following template and I think the devil hides here

<div [ngSwitch]="loading | async">
    <template [ngSwitchCase]="true">
      <md-progress-circle mode="indeterminate"></md-progress-circle>
    </template>
    <template ngSwitchDefault>
        <ng-content></ng-content>
    </template>
</div>

and then we have the app.html looking like

<load-route-progress>
  <router-outlet></router-outlet>
</load-route-progress>

the part with lazy module and tabs is identical (but I don't think it has to do with lazy, I think it has to do with ngSwitch hiding router-outlet. So if you navigate to the lazy module, the page with tabs will stuck. If you remove load-route-progress component from markup, everything is fine. So the question is, is it a bug or feature? Maybe it is not allowed to remove router-outlet from dom (it is working as expecting with anything else though until beta 11-3) or is it really some bug in Material Tabs?

P. S. if you still cannot reproduce the problem, I will upload minimal project to github

chpasha avatar Dec 11 '16 18:12 chpasha

Thanks, this looks promising. I'll try it out a bit later.

crisbeto avatar Dec 11 '16 18:12 crisbeto

Thanks @chpasha, now it happened! I actually had to slow down the hiding of the progress since it doesn't break if it hides too fast. On one hand it seems weird to have a ngSwitch over a router outlet, however I'm not sure that's the cause. I put in your example in our demo app and the only component that breaks is the tabs. Another interesting thing is that the loading has to be slow in order for it to happen, e.g. if I slow it down 500ms it doesn't happen, however after 1000ms and 2000ms it does. For reference, here's what I changed the route subscriber to:

this.subscription = router.events.subscribe(s => {
  if (s instanceof NavigationStart) {
    this.loading.next(true);
  }
  if (s instanceof NavigationEnd) {
    setTimeout(() => this.loading.next(false), 1000);
  }
});

As a side-note, my initial hunch was that it may also be the circular progressbar causing it, but if I replace it with plain text it still happens.

crisbeto avatar Dec 11 '16 20:12 crisbeto

Great that you could reproduce the problem. I still think it has to do with the lifecycle. I replaced switch with two divs with [hidden] attribute and the problem was gone. And don't forget those experiments with ngIf when adding tabs after the main component has rendered, it also worked fine.

chpasha avatar Dec 12 '16 08:12 chpasha

True, but in that case any other components would break as well. I'll take a better look into this today.

crisbeto avatar Dec 12 '16 08:12 crisbeto