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

bug: Vue lifecycle hooks are only called in top level component #27026

Closed
3 tasks done
aparajita opened this issue Mar 25, 2023 · 3 comments
Closed
3 tasks done

bug: Vue lifecycle hooks are only called in top level component #27026

aparajita opened this issue Mar 25, 2023 · 3 comments
Labels

Comments

@aparajita
Copy link

Prerequisites

Ionic Framework Version

v7.x

Current Behavior

The Vue lifecycle hooks (onIonViewWillEnter, etc.) are only called in the top level component for any given page, whether or not that component's template contains IonPage. Lifecycle hooks will never be called in a child component, even if their template contains IonPage.

Expected Behavior

The documentation is silent on the restriction imposed by the current behavior. I expected the lifecycle hooks to work from anywhere within the component hierarchy.

Steps to Reproduce

  1. Open the stackblitz project.
  2. Note that in Tab one, the lifecycle hooks are in a child component and are not called; no alert appears.
  3. Click on Tab two. An alert appears for onIonViewWillEnter and onIonViewDidEnter, since they are called from within the top level component.

Code Reproduction URL

https://stackblitz.com/edit/angular-wmuse1?file=src/views/TabTwo.vue

Ionic Info

Run from StackBlitz project:

Ionic:

Ionic CLI : 6.20.9

Utility:

cordova-res : not installed globally
native-run : not installed globally

System:

NodeJS : v16.14.2
npm : 7.17.0
OS : Linux 5.0

Additional Information

I am not the only person who has run into this issue. If it is not feasible to make the lifecycle hooks work in a child component, the documentation should be updated to clearly state the restriction that they only work within the top level component of a view.

@ionitron-bot ionitron-bot bot added the triage label Mar 25, 2023
@liamdebeasi liamdebeasi self-assigned this Mar 27, 2023
@liamdebeasi
Copy link
Contributor

Thanks for the report. I can reproduce this behavior, but Ionic is working as intended. Lifecycle hooks are called on the component that the router maps the URL to. In this case, your /one route maps to the TabOne component. As a result, the lifecycle hooks will be called on TabOne and not TabOneChild.

I will clarify this behavior on the docs.

@aparajita
Copy link
Author

Thanks! Put that in the docs and you can save us a few gray hairs. 😁

@ionitron-bot
Copy link

ionitron-bot bot commented Apr 26, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Apr 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants