-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_register(menu: MenuI): void; | ||
_unregister(menu: MenuI): void; | ||
|
||
getMenus(): Promise<HTMLIonMenuElement[]>; | ||
getOpenSync(): HTMLIonMenuElement | undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getOpenSync
doesn't actually exist on the menu controller. However, _getOpenSync
does so I think this was a typo.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Maybe add a comment on the tests that they were created for issue 28337, like the annotations in core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Thanks for the quick turnaround on this!
Issue number: resolves #28337
What is the current behavior?
Duplicate instances of
menuController
are being created in@ionic/angular
.ion-menu
registers itself in themenuController
from@ionic/core
, but theMenuController
from@ionic/angular
uses themenuController
from@ionic/core/components
. This is how the overlay providers work too. Normally, this is not a problem. However,menuController
caches 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,
menuController
B does not know about the menus inmenuController
A. 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?
MenuController
in Ionic Angular to accept amenuController
instance. This allows@ionic/angular
to pass themenuController
from@ionic/core
and for@ionic/angular/standalone
to pass themenuController
from@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