Custom implementation of DefaultInstantiator

Hey folks,

i have a custom implementation of defaultInstantiator like

public <T> T getOrCreate(Class<T> type) {
	if (!this.components.containsKey(type)) {
		final T instance = ReflectTools.createInstance(type);
		this.components.put(type, (Component) instance);

		return instance;
	} else {		
		final Component component = this.components.get(type);		
		return (T) component;
	}
}

( by the way - this is a optimistic implemantation. )
as long as i use “router-link” instead of a simple anchor, everthing works fine.
using a anchor produces an “internal error” like

com.vaadin.flow.server.ServiceException: java.lang.IllegalStateException: Can't move a node from one state tree to another
...
java.lang.IllegalStateException: Can't move a node from one state tree to another
	com.vaadin.flow.internal.StateNode.doSetTree(StateNode.java:657)
	com.vaadin.flow.internal.StateNode.lambda$setTree$3(StateNode.java:364)
	com.vaadin.flow.internal.StateNode$$Lambda$3220/707061991.accept(Unknown Source)
	com.vaadin.flow.internal.StateNode.visitNodeTree(StateNode.java:616)
	com.vaadin.flow.internal.StateNode.setTree(StateNode.java:364)
	com.vaadin.flow.internal.StateNode.setParent(StateNode.java:264)

now i can not really figure out why this happens. why state tree is not updated
automatically during parent obtains child-element?

thx for help!

hello again,

I was wondering about the default implementation of “DefaultInstantiator”.
In particular the “getOrCreate” method. The default implementation always creates a new instance.
In my opinion the “get”-part of the method name suggests that there is some kind of caching mechanism.
Why does Vaadin not deliver a better implementation of “DefaultInstantiator” with caching possibilities?

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