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

ngZone: 'noop' option doesn't work with Angular Material components #9169

Closed
chasemgray opened this issue Dec 30, 2017 · 28 comments
Closed

ngZone: 'noop' option doesn't work with Angular Material components #9169

chasemgray opened this issue Dec 30, 2017 · 28 comments
Labels
area: many Area label for issues related to many components feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@chasemgray
Copy link

Bug, feature request, or proposal:

What is the expected behavior?

Buttons, sidenav, selects, input fields, etc. should function normally when ngZone: 'noop' is specified.

What is the current behavior?

If you enabled ngZone: 'noop' most Angular Material components break.

What are the steps to reproduce?

Launching a an app which uses material components using .bootstrapModule(AppModule, {ngZone: 'noop'}); results in components that do not work properly.

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

Angular added in 'noop' so that apps that control their own change detection using OnPush can disable the extra overhead of zones. Is the material team planning to support this?

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

Angular 5.0, Material 5.0

Is there anything else we should know?

@jelbourn jelbourn added feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent labels Jan 2, 2018
@jelbourn jelbourn self-assigned this Jan 2, 2018
@jelbourn
Copy link
Member

jelbourn commented Jan 2, 2018

This is on our roadmap but we don't have an ETA currently

@bulash
Copy link

bulash commented May 24, 2018

same problem, may be status changed or we can hope for some ETA?

@jelbourn
Copy link
Member

We're still in the same state where Angular core would need additional features for us to be able to do this.

@jnlmmln
Copy link

jnlmmln commented Mar 25, 2019

Any updates about this issue?

@adrianpiesiak
Copy link

I'd also love to get an update on this one. I really like using materials but now it seems that it's a no-go when high performance is a must and noop is used :/

@claudiuconstantin
Copy link

News here?

@mucbits
Copy link

mucbits commented Aug 9, 2019

Any update on this?

@SerkanSipahi
Copy link
Contributor

Any Update?

@ms-dosx86
Copy link

Hello?

@DrewLandgraveCbsi
Copy link

DrewLandgraveCbsi commented Jan 29, 2020

@jelbourn,
Any update on this?

Currently I'm not able to use @angular/elements using @angular/components. When I try to use these components in another angular project it complains that
zone.js has detected that ZoneAwarePromise (window|global).Promise has been overwritten.

@DrewLandgraveCbsi
Copy link

DrewLandgraveCbsi commented Jan 29, 2020

So for anyone running into my issue, where you're trying to build an @angular/elements component that also uses @angular/components(material) and zone is complaining, I found a fix.

So what you're going to need to do is build your @angular/elements project and concat your built files while EXCLUDING the polyfills. Here's the scripts in my package.json

"build": "ng build --prod --output-hashing=none",
"package-es5": "bash -c 'cat dist/angular-topic-control-with-service-worker/{runtime-es5,styles-es5,scripts,main-es5}.js > dist/angular-topic-control-with-service-worker/package-es5.js'",
"package-es2015": "bash -c 'cat dist/angular-topic-control-with-service-worker/{runtime-es2015,styles-es2015,scripts,main-es2015}.js > dist/angular-topic-control-with-service-worker/package-es2015.js'",
"bundle": "npm run build && npm run package-es5 && npm run package-es2015",

I run npm run bundle. Then you'll take the package*.js files and add them to your other angular app. I put my in a src/custom-elements folder.

In your angular.json you'll add the package to the scripts array

"scripts": [
    {
        "input": "node_modules/document-register-element/build/document-register-element.js"
    },
    "src/custom-elements/package-es2015.js"              
]

Then build your app and it shouldn't complain about the zone issue anymore. Granted this does not fix the problem with noop zones, however it does allow you to build custom elements with angular material. I successfully did it with MatInputs and MatFlatTree's

@andrewseguin andrewseguin added the area: many Area label for issues related to many components label Jun 11, 2020
@ievgennaida
Copy link

I would like to use IVY with markDirty, but I cannot while material components are not working.

@Jordan-Hall
Copy link

@chrisguttandin to use positionStrategy without zone if you call "updatePosition" after attaching it works fine

    const config = new OverlayConfig({
      positionStrategy: this.overlay
        .position()
        .flexibleConnectedTo(this.dropdown)
        .withPositions([
          {
            originX: 'start',
            originY: 'bottom',
            overlayX: 'start',
            overlayY: 'top',
          },
        ]).withPush(true),
    });

    this.fusilliOverlayRef = this.overlay.create(config);
    this.fusilliOverlayRef.backdropClick().subscribe(() => {
      this.fusilliOverlayRef.dispose();
    });

    this.fusilliOverlayRef.attach(
      new ComponentPortal(TravellersComponent, this.viewContainerRef)
    );

    this.fusilliOverlayRef.updatePosition();
  }```

@chrisguttandin
Copy link

Thanks a lot @Jordan-Hall. That is very helpful information.

@Jordan-Hall
Copy link

Another note. if you happen to use angular lifecycle hooks. Make sure you manually call ngOninit... Just spent ages with a dev fixing his code to finally notice he used lifecycle

@jon9090
Copy link

jon9090 commented Feb 18, 2022

ngrx and rx-angular give us a way to create application without zonejs.
I wish that material remove zonejs so I can get rid of this library in my application. this is only thing is missing.

@jelbourn its 2022, any news? it's in the plan of the team?

@ywarezk
Copy link

ywarezk commented Jul 9, 2022

I wrote this library to help with angular zoneless apps.
The library will also make material work in zoneless mode (and will also make every 3rd party that does not support zoneless work)
link to the library: az-zoneless.
The library also expose events that will trigger ChangeDetectorRef.detectChanges.
For example:

<button (azClick)="doSomething()">this click works in zoneless since it calls ChangeDetectorRef.detectChanges()</button>

@haskelcurry
Copy link

Any updates on this?

@DibyodyutiMondal
Copy link

I noticed that for the most part, angular material works fine without zone. Except in cases like snackbar or dialog. The animation/position are wrong. I think it's because they rely on change detection to apply correct position after the thing has opened, but no zone = no change detection.

But, we can now use signals to do it, right? Pretty please?

@Casimodo72
Copy link

Any news on this matter?
"In Angular 17, signals were released as stable (except for the effect() function)".
Can we at least expect material to move forward in the foreseeable future (months not years)? Would be great to have some updated info in order to make decisions on our side.

@Jordan-Hall
Copy link

For Tabs I've found using @rx-angular/cdk

    import { RX_RENDER_STRATEGIES_CONFIG, RxStrategyProvider } from '@rx-angular/cdk/render-strategies';

    private strategies = inject(RX_RENDER_STRATEGIES_CONFIG);
    constructor(private strategyProvider: RxStrategyProvider, private cdr: ChangeDetectorRef) {}
    
    tick() {
    this.strategyProvider.scheduleCD(this.cdr, { strategy: this.strategies.primaryStrategy});
  }

Lastly in the HTML you can use the <mat-tab-group (focusChange)="tick()" this will update the component. Only thing not figured out is fixing the inital focus

@Casimodo72
Copy link

The lack of transparency about whether Material will go Signals in the foreseeable future makes me believe that we get stuck with it as it is and zone.js will still be needed in the coming years.
My context is that I want Angular to transpile to native async/await - which is seemingly not possible if zone.js is still in the game.

@jelbourn
Copy link
Member

jelbourn commented Jan 3, 2024

Angular material and cdk will both adopt signals when support is further along. It's a long-term goal for the team to ensure that all of Angular's first-party offerings are signal-based with no zonejs dependency. It's a long road, though, as it involves many breaking changes that need gradual rollouts, backwards compatibility, and migration tooling.

@atscott
Copy link
Contributor

atscott commented Apr 11, 2024

I'm going to close this as complete now thanks to the work done by @mmalerba to remove ngZone.onStable and ngZone.onMicrotaskEmpty. Note that if you are using ngZone: 'noop', you do need to run change detection through ApplicationRef.tick.

@atscott atscott closed this as completed Apr 11, 2024
@DibyodyutiMondal
Copy link

This is so amazing! 🤩
So then it will be a part of the v18 release? Will it be considered as 'stable' or 'development' at that point?

@JeanMeche
Copy link
Member

Zoneless support will be experimental in v18.

@atscott
Copy link
Contributor

atscott commented Apr 21, 2024

So then it will be a part of the v18 release? Will it be considered as 'stable' or 'development' at that point?

For this repository, the compatibility is just there. There’s nothing to enable or disable so there’s not really a “status” so to speak.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: many Area label for issues related to many components feature This issue represents a new feature or feature request rather than a bug or bug fix P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests