flow icon indicating copy to clipboard operation
flow copied to clipboard

circular dependency bug while using layouts

Open avdhootu27 opened this issue 11 months ago • 6 comments

Description of the bug

I have a MainLayout and some other routes which are child of MainLayout. I have a drawer in MainLayout which has RouterLinks to those child routes. Now the issue is I have to mention class names of child layouts while creating the RouterLinks in MainLayout. And I have to mention MainLayout.class as layout parameter in Route annotation in child view classes. So it is causing circular dependency. So is there any way to remove this circular dependency

Expected behavior

Sonar should not give circular dependency bug here

Minimal reproducible example

Just create a MainLayout add RouterLinks to it and add MainLayout.class as layout parameter in Route annotation in child view classes

Versions

  • Vaadin / Flow version: 14.11.0
  • Java version: 11
  • OS version: MacOS Ventura 13.6.1
  • Browser version (if applicable):
  • Application Server (if applicable):
  • IDE (if applicable):

avdhootu27 avatar Mar 15 '24 05:03 avdhootu27

Well.. you are adding that direct reference yourself.. you can get all available routes from the RouterRegistry if you are worried about Sonarqube and go the full generic "route".

knoobie avatar Mar 15 '24 05:03 knoobie

Can you please tell me how to do it? I want to create RouterLink for each view in MainLayout, so how to use RouterRegistry for it?

avdhootu27 avatar Mar 15 '24 05:03 avdhootu27

https://vaadin.com/docs/latest/routing/dynamic#getting-registered-routes-and-listening-for-changes

knoobie avatar Mar 15 '24 06:03 knoobie

Thanks

avdhootu27 avatar Mar 15 '24 09:03 avdhootu27

I tried it but it doesn't solve circular dependency bug. This solution is good to remove class references from MainLayout but in child classes still MainLayout reference is there

avdhootu27 avatar Mar 15 '24 10:03 avdhootu27

That's not called "circular".

knoobie avatar Mar 15 '24 10:03 knoobie

AtRoute indeed needs a layout component class as a parameter, but I don't think this means the circular dependency in terms, for example, how Maven treats it. This is more like a logical binding of your routes and main layout.

We don't know what we can do in Flow to address the issue that Sonar gives you. Proposed for closure.

If you have more details from Sonar that could give us more insights, please provide it to us.

mshabarov avatar Mar 19 '24 12:03 mshabarov