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

Custom Instantiator breaks ComponentTracker #21086

Open
mvysny opened this issue Mar 5, 2025 · 0 comments
Open

Custom Instantiator breaks ComponentTracker #21086

mvysny opened this issue Mar 5, 2025 · 0 comments

Comments

@mvysny
Copy link
Member

mvysny commented Mar 5, 2025

Description of the bug

When a CustomInstantiator overrides getOrCreate(), this breaks the ComponentTracker which now starts reporting creation points as Component 'com.vaadin.starter.skeleton.MyInstantiator' at 'MyInstantiator.java' (getOrCreate LINE 15).

Expected behavior

The ComponentTracker should correctly track component creation even if custom instantiator is used.

Minimal reproducible example

@Route("")
public class MainView extends VerticalLayout {
    public MainView() {
        add(ComponentTracker.findCreate(this).toString());
    }
}
public class MyInstantiator extends DefaultInstantiator {
    public MyInstantiator(VaadinService service) {
        super(service);
    }

    @Override
    public <T> T getOrCreate(Class<T> type) {
        return super.getOrCreate(type);
    }

    public static class Factory implements InstantiatorFactory {
        @Override
        public Instantiator createInstantitor(VaadinService service) {
            return new MyInstantiator(service);
        }
    }
}

(don't forget to register the instantiator via META-INF/services as documented at https://vaadin.com/docs/latest/flow/advanced/custom-instantiators ).

When the instantiator is not enabled, the route correctly prints:

Component 'com.vaadin.starter.skeleton.MainView' at 'MainView.java' (<init> LINE 12)

When the custom instantiator is enabled, the route prints:

Component 'com.vaadin.starter.skeleton.MyInstantiator' at 'MyInstantiator.java' (getOrCreate LINE 15)
Online

This is not helpful especially in connection with the infamous "Can't move a node from one state tree to another. If this is intentional, first remove the node from its current state tree by calling removeFromTree." exception.

Versions

  • Vaadin / Flow version: 24.6.6
  • Java version: 17
  • OS version: Ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant