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

Error when using @RouteScope in components - version 1.3.18 (and also 1.3.17) #129

Open
brunovianarezende opened this issue Aug 11, 2022 · 7 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@brunovianarezende
Copy link

brunovianarezende commented Aug 11, 2022

I have a component annotated with @RouteScope and when I try to init the app in the test, I get the error:

Caused by: java.lang.IllegalStateException: UI bean store is not found by the initial UI id via the key 'uid-1' and it's not found by the key 'win-ROOT-2521314-0.2626611481' after relocation.
	at com.vaadin.flow.spring.scopes.VaadinRouteScope$RouteStoreWrapper.relocateStore(VaadinRouteScope.java:123)
	at com.vaadin.flow.spring.scopes.VaadinRouteScope$RouteStoreWrapper.lambda$getBeanStore$b500751e$1(VaadinRouteScope.java:100)
	at com.vaadin.flow.component.page.Page.retrieveExtendedClientDetails(Page.java:567)
	at com.github.mvysny.kaributesting.v10.MockPage.retrieveExtendedClientDetails(MockVaadin.kt:421)
	at com.vaadin.flow.spring.scopes.VaadinRouteScope$RouteStoreWrapper.getBeanStore(VaadinRouteScope.java:99)
	at com.vaadin.flow.spring.scopes.VaadinRouteScope.getBeanStore(VaadinRouteScope.java:412)
	at com.vaadin.flow.spring.scopes.AbstractScope.get(AbstractScope.java:44)
	at com.vaadin.flow.spring.scopes.VaadinRouteScope.get(VaadinRouteScope.java:67)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:371)
	... 103 more

it seems to me this error is caused by this commit: 7d0435e. I tested using version 1.3.16 and it works ok.

This is the code in my test class:

  private static final Routes routes = new Routes().autoDiscoverViews("the.package");

  @Autowired
  private ApplicationContext ctx;

  @BeforeEach
  public void mockVaadin() {
    final Function0<UI> uiFactory = UI::new;
    final SpringServlet servlet = new MockSpringServlet(routes, ctx, uiFactory);
    MockVaadin.setup(uiFactory, servlet);
  }

  @BeforeEach
  public void navigate() {
    UI.getCurrent()
        .navigate(AView.class);
    _assertOne(AView.class);
  }

and this is what I have in my POM:

    <dependency>
        <groupId>com.github.mvysny.kaributesting</groupId>
        <artifactId>karibu-testing-v10-spring</artifactId>
        <version>1.3.18</version>
        <scope>test</scope>
    </dependency>

The code that triggers the bug is something like:

@Route(...)
public class ARoute {
...
  @Inject
private TheClassThatCausesProblem the classe;
...
}

and:

@RouteScope
public class TheClassThatCausesProblem extends HorizontalLayout {
...
}
@mvysny mvysny self-assigned this Aug 12, 2022
@mvysny mvysny added the bug Something isn't working label Aug 12, 2022
@mvysny
Copy link
Owner

mvysny commented Aug 12, 2022

Thank you for letting me know 👍 I'll try to add this test to Karibu itself, hopefully I'll be able to reproduce it on my machine. It's good to know that 1.3.16 worked okay. @brunovianarezende could you please check 1.3.17 whether it's also affected?

@mvysny mvysny added the question Further information is requested label Aug 12, 2022
@mvysny
Copy link
Owner

mvysny commented Aug 12, 2022

Also, which version of vaadin-spring.jar are you using please, and which Vaadin version?

@brunovianarezende
Copy link
Author

Thank you for letting me know +1 I'll try to add this test to Karibu itself, hopefully I'll be able to reproduce it on my machine. It's good to know that 1.3.16 worked okay. @brunovianarezende could you please check 1.3.17 whether it's also affected?

Yes, 1.3.17 is affected too.

@brunovianarezende
Copy link
Author

Also, which version of vaadin-spring.jar are you using please, and which Vaadin version?

We use:

    <dependency>
      <groupId>com.vaadin</groupId>
      <artifactId>
        vaadin-spring-boot-starter
      </artifactId>
      <version>${vaadin.version}</version>
    </dependency>

where ${vaadin.version} is equal to 23.1.1, i.e. vaadin-spring is 23.1.1 and vaadin is 23.1.1.

@mvysny
Copy link
Owner

mvysny commented Aug 25, 2022

Sorry - I tried to upgrade Spring in Karibu-Testing in hopes to create a reproducible test, but Spring failed with random class incompatibility exceptions. However, let me try to figure out a blind workaround.

@mvysny
Copy link
Owner

mvysny commented Aug 25, 2022

The new implementation of retrieveExtendedClientDetails() seems to interfere with Spring. It was introduced during the fix of #118 . I'll add a flag to turn this functionality off as a workaround.

mvysny added a commit that referenced this issue Aug 25, 2022
@mvysny mvysny removed the question Further information is requested label Aug 25, 2022
@mvysny
Copy link
Owner

mvysny commented Aug 25, 2022

The flag is called fakeExtendedClientDetails and it can be turned off starting with Karibu 1.3.20. Please see the documentation for more details. This is just a workaround though - a proper solution still needs to be found.

I'll therefore keep this ticket open. If someone feels brave enough to upgrade Spring in Karibu-Tests and write a test that reproduces this issue, please go ahead and create a PR. I'll merge the PR and proceed to fix the issue properly.

@mvysny mvysny added the help wanted Extra attention is needed label Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants