Fragment's AttachEvent not triggered when there are mutliple sub-fragments

Hi Jmix Support team,

I have encountered a scenario where there is 3 fragments, Fragment A, B, and C for instance.
Fragment A belongs to my DetailView, Fragment B and C both belongs to Fragment A.
All fragments have an AttachEvent where I use to configure some properties for my system, however for Fragment C the AttachEvent is not triggered as expected. It seems like there is a bug when there are 2 fragments inside of a fragment, the second sub-fragment will not fire the AttachEvent.
Could you please look into this bug? Thank you.

Hi,

Could you please attach a demo project that reproduces the issue?

Regards,
Gleb

Subfragment Demo Project

Here is a demo project requested to showcase the error mentioned above.

In this project there are Fragment A and Fragment B, which both extends CustomFragment that extends Fragment from Jmix.

In our CustomFragment, there is a method that needs to be called onAttach, so we used the addAttachListener() to add that in and expect it to be triggered.
All fragments have their own respective onHostAttach event as well, which is expected to trigger after the onAttach event that is stated in CustomFragment.

In Fragment A, there are 2 tabs, each with their own instance of Fragment B.
The issue right now is, the onAttach event of Fragment B from the “second” tab did not trigger until user selects the tab, only then it will trigger.
However onHostAttach events for all fragments are triggered when the parent view shows on screen.

My question is:
How come the onHostAttach event will trigger for the “unselected” tab’s Fragment B, but the onAttach event that is added through addAttachListener() not trigger accordingly ?
Is this an expected behaviour? Or how can I achieve the results I expected, which is:

  1. Trigger all the attachEvents added through addAttachListener() in CustomFragment.
  2. Trigger all the onHostAttach events after that.

Screenshot 2025-06-26 104859
This is a snapshot of my logs, you should be able to get this as well when you open the SubfragmentDemoView.

Regards,
Wei Jian.

Hi,

Thank you fir the demo project and the detailed description. The described behaviour is not a bug. The content of each tab is added when this tab is selected for the first time.

Below the DOM tree when the fist tab is selected, only one <vaadin-vertical-layout> (which represents the tab content) element is present:
Screenshot 2025-06-26 at 15.22.48

After we select the second tab, both <vaadin-vertical-layout> are present:
Screenshot 2025-06-26 at 15.22.57

Since I’m not aware with the logic you’re implementing, the general advice would be to subscribe to the other lifecycle events of the host view/fragment.

Regards,
Gleb