NG-ZORRO / ng-zorro-antd

Angular UI Component Library based on Ant Design
https://ng.ant.design
MIT License
8.87k stars 3.94k forks source link

Microfrontend (module federation / native federation) support #8829

Open strigefleur opened 1 month ago

strigefleur commented 1 month ago

What problem does this feature solve?

Frontend federation makes it so that one shell-app loads multiple module-apps. NgAnt has some features (NzMessageService, NzNotificationService etc) that appear to be root-bound via providedIn: 'root' decorator options and thus leading to multiple instances of same module loaded within federated frontend.

As of Angular 9 there's providedIn: 'platform' decorator option that should replace providedIn: 'root' in such cases I suppose.

As far as it's impossible to create service of 'platform' level having internal 'root' level dependency it's show stopper for some scenarios involving NgAnt framework.

I'm not sure that's the only concern that should be cared of so would love to have some feedback.

What does the proposed API look like?

@Injectable({
  providedIn: 'platform'
})
export class NzMessageService extends NzMNService { /* ... */ }
adchsm commented 4 weeks ago

In a barebones Angular 16 and 17 app, as soon as I add the ng-zorro-antd package, native federation errors and the app fails to serve. Not to jump on your ticket, but I'd also like to see for native federation.

strigefleur commented 3 weeks ago

@adchsm well, you can bypass initial native federation issues by manually importing problematic packages to devDependencies and then adding same list to nf skip:

      'd3-shape',
      'd3-drag',
      'd3-selection',
      'd3-zoom',
      'd3-transition',
      'dagre-compound',

So unless you have to deal with singleton this and singleton that, it's gonna work.

strigefleur commented 3 weeks ago

Also I did some research on providedIn: 'platform' and it appears to provide more issues than solving: due to being 'platform injector' it's not just copy-paste replacement. Perhaps my initial issue is solvable by correct provider import layers between mfe and shell, omw.