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

Component Life Cycle Methods not called as documented #2954

Open
JulianLang opened this issue Jul 5, 2021 · 5 comments
Open

Component Life Cycle Methods not called as documented #2954

JulianLang opened this issue Jul 5, 2021 · 5 comments
Assignees
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team

Comments

@JulianLang
Copy link

JulianLang commented Jul 5, 2021

Stencil version:

 @stencil/core@2.3.0

I'm submitting a:

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:

Consider the following structure:

<!-- toggle group A -->
<toggle-group>
   <toggle-button></toggle-button>

   <!-- nested toggle group B -->
   <toggle-group>
      <toggle-button></toggle-button>
   </toggle-group>
</toggle-group>

We have two nested toggle-groups where each should only find their own children. I rely on life-cycle hooks, so that the nested group (B) should look for its children first, mark them as "already belonging", then the next higher toggle-group (A) should search for its children (those, that are not marked yet) and so on.

Unfortunately I see the following life-cycle behavior:

ToggleGroup A:  connectedCallback
ToggleGroup B: connectedCallback
ToggleGroup A:  componentDidLoad
ToggleGroup B: componentDidLoad

which is not what I expect due to stencil's documentation.

Expected behavior:

The componentDidLoad life cycle hook gets called after all children's (slotted or not) as documented here:

So it should be:

ToggleGroup A:  connectedCallback
ToggleGroup B: connectedCallback
ToggleGroup B: componentDidLoad
ToggleGroup A:  componentDidLoad

Steps to reproduce:

  • Build a structure similar to the one given above
  • add connectedCallback and componentDidLoad to each parent-component (in my case toggle-group) with a console.log

Related code:

// insert any relevant code here

Other information:

There were already some issues about this before, but unfortunately they got closed. I hope this issue will make it, as I find it is fundamental to any component framework, that life-cycle hooks can be relied on.

@ionitron-bot ionitron-bot bot added the triage label Jul 5, 2021
@rwaskiewicz
Copy link
Contributor

Hey @JulianLang 👋

Thanks for the detailed bug report! It'd be super helpful if you could create a minimal reproduction case, would you be able to create a repository in GitHub that includes the app structure you describe above, and the exact steps needed to reproduce the issue (e.g. which NPM scripts we'd need to run)? That'd be a huge help to me and the team! 🙂

@JulianLang
Copy link
Author

JulianLang commented Jul 20, 2021

Hi @rwaskiewicz ,

I pushed the repro here: https://github.com/JulianLang/stencil-bug-lifecycle-hooks

You find some steps to get started within the README.
Reloading the app several times will show sporadic changes of the order of console logs.

But an interesting thing is, that I could not reproduce the original issue, that the toggle-groups didLoad are not called in the right order. But since the order is not stable anyway, I assume that was just luck^^

Some examples *:

* (sorry, I renamed Outer to A and Inner to B in the meantime of the screenshots, but you can reproduce it with my repro for better understanding anyways). Also even in one screenshot, the expected order (in regards to connectedCallback order vs didLoad order is not as I would expect.

  • image
  • image
  • image

If you need additional help or info, I'm glad to help :)

@rwaskiewicz
Copy link
Contributor

Thank you so much!

@rwaskiewicz rwaskiewicz self-assigned this Jul 25, 2021
@splitinfinities splitinfinities added the Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team label Aug 17, 2021
@JulianLang
Copy link
Author

Hey, I just wanted to recheck what's the status of this issue :) Is there anything I can help with?

@pierrebaronqumu
Copy link

Looks related to #3580

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Needs Investigation This PR or Issue should be investigated from the Stencil team
Projects
None yet
Development

No branches or pull requests

4 participants