fix(angular): do not create duplicate menuController instances - #28343
Conversation
b4dc849 to
ac21cc3
Compare
| private menuController; | ||
|
|
||
| // TODO Now - Add type | ||
| constructor(private menuCtrl: any) { |
There was a problem hiding this comment.
I think we should remove the @Injectable from this class in common. We aren't using it with dependency injection in the extending implementations. If we did based on the current implementation, Angular would not know how to resolve menuCtrl and would throw an exception.
Since we are treating this as a base class of logic that is extended in the hydrated and custom elements implementations, I think we are safe to remove it.
re: Type, could you import the type from of menuController from @ionic/core/components? We already have some instances in the common package where we are assuming the CE build exists in the distributed package.
| _unregister(menu: MenuI): void; | ||
|
|
||
| getMenus(): Promise<HTMLIonMenuElement[]>; | ||
| getOpenSync(): HTMLIonMenuElement | undefined; |
There was a problem hiding this comment.
getOpenSync doesn't actually exist on the menu controller. However, _getOpenSync does so I think this was a typo.
thetaPC
left a comment
There was a problem hiding this comment.
LGTM. Maybe add a comment on the tests that they were created for issue 28337, like the annotations in core.
sean-perkins
left a comment
There was a problem hiding this comment.
Looks good to me. Thanks for the quick turnaround on this!
Issue number: resolves #28337
What is the current behavior?
Duplicate instances of
menuControllerare being created in@ionic/angular.ion-menuregisters itself in themenuControllerfrom@ionic/core, but theMenuControllerfrom@ionic/angularuses themenuControllerfrom@ionic/core/components. This is how the overlay providers work too. Normally, this is not a problem. However,menuControllercaches references to registered menus in each controller instances:ionic-framework/core/src/utils/menu-controller/index.ts
Line 14 in dcbf451
This means that since there are two different controllers,
menuControllerB does not know about the menus inmenuControllerA. The end result is that the menu controller used in developer applications did not have references to the registered menus, which gave the impression that the menu controller did not work.What is the new behavior?
MenuControllerin Ionic Angular to accept amenuControllerinstance. This allows@ionic/angularto pass themenuControllerfrom@ionic/coreand for@ionic/angular/standaloneto pass themenuControllerfrom@ionic/core/components.Note: Overlay controllers don't need this change per-se since they don't cache references to overlays internally (they just query the DOM). However, I think it would be good to have a consistent architecture here, so I'll put up a separate PR that makes this change for overlays too.
Does this introduce a breaking change?
Other information
Dev build:
7.5.1-dev.11697123035.1ee6b4a2