question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HasUrlComponent#setParameter is invoked clicking on self-referencing links

See original GitHub issue

The setParameter method of HasUrlComponent gets invoked even if the user is already in there; this means all the operations the method does with the parameter are executed again for the same component instance. For example:

public class MainLayout extends VerticalLayout implements RouterLayout {

    public MainLayout() {
        add(new RouterLink("One", Foo.class, 1);
        add(new RouterLink("Two", Foo.class, 2);
        add(new RouterLink("Three", Foo.class, 3);
    }
}

@Route(value = "foo", layout = MainLayout.class)
public class FooCard extends VerticalLayout implements HasUrlParamenter<Long> {

    @Override
    public void setParameter(BeforeEvent event, Long parameter) {
        composeLayoutFor(parameter);
    }
}

If the user is at /foo/1 and clicks on link “One”, composeLayoutFor is invoked for the same instance even if the location does not change, for example duplicating components that the method might add (which depends on the parameter value).

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
plekucommented, Nov 20, 2018

but the current implementation always reuses based on the code snippet referenced in the above comment.

Should probably also consider in https://github.com/vaadin/spring/issues/263 that it should be possible to always create a new view instance on navigation for Spring too. Maybe when prototype scope is used ?

0reactions
Legiothcommented, Nov 20, 2018

Making it configurable e.g. through the @Route annotation sounds like a good way to go. I guess the API would then be something like @Route(value = "foo", reuseInstance = false). Should preferably also take router layouts into account since those are also reused using the same mechanism.

I think the comment about Spring can be disregarded. The original router prototype implementation delegated the decision whether to reuse an instance or create a new one to Spring, but the current implementation always reuses based on the code snippet referenced in the above comment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL Engine server config reference - Hasura
GraphQL Engine server config reference. Introduction​. Every GraphQL engine command is structured as: $ graphql-engine <server-flags> serve <command-flags>.
Read more >
graphql – CSS-Tricks
We imported the Link component from Gatsby and then wrapped the post title with the Link component and reference the slug of the...
Read more >
sitemap-questions-84.xml - Stack Overflow
... .com/questions/1750757/restarting-a-self-updating-python-script 2020-12-02 ... /questions/5948205/chrome-open-link-in-new-tab-not-firing-the-click-event ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found