Error "Can't move a node from one state tree to another." when re-adding a previously removed component after refreshing with @PreserveOnRefresh
See original GitHub issueDescription of the bug
If a component is added and then removed from a component that is preserved on refresh, trying to add it again after refreshing results in the error
java.lang.IllegalStateException: 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
Minimal reproducible example
Code below. Steps to reproduce:
- Click the first button
- Click the second button
- Refresh the page
- Click the first button again
import com.vaadin.flow.component.Text;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PreserveOnRefresh;
import com.vaadin.flow.router.Route;
@Route("")
@PreserveOnRefresh
public class MainView extends VerticalLayout {
public MainView() {
Text text1 = new Text("Text 1");
Text text2 = new Text("Text 2");
Div container = new Div();
Button button1 = new Button("Set text 1", e -> {
container.removeAll();
container.add(text1);
});
Button button2 = new Button("Set text 2", e -> {
container.removeAll();
container.add(text2);
});
add(button1, button2, container);
}
}
Expected behavior
Text 2
is replaced by Text 1
.
Actual behavior
An exception is thrown
java.lang.IllegalStateException: 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
Versions:
- Vaadin 14.1.27, Flow 2.1.9
- Java version: openjdk 11.0.4
- OS version: Windows 10
- Application Server (if applicable): Spring Boot embedded Tomcat
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
“Can't move a node from one state tree to another” error in ...
Looks it is due the same reason @Sathya had mentioned above. If you add a component, twice and refresh the page, you would...
Read more >java - "Can't move a node from one state tree to another" when ...
Whenver I click logout, I successfully get redirected to the LogIn View, but instead of logging in, it says "Assertion Error: No child...
Read more >Preserving and Resetting State - React Docs Beta
State is isolated between components. React keeps track of which state belongs to which component based on their place in the UI tree....
Read more >Troubleshoot—ArcGIS Online Help | Documentation
When I add an OGC WMS or WMTS layer to my map, I get an error that says the layer's coordinate system doesn't...
Read more >Changelog | Cypress Documentation
Breaking Changes: Cypress dropped support for Node.js 12, 15 and 17. Those versions have reached end-of-life. Installing Cypress on your system ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed.
Thank you very much for precise and short steps to reproduce. 👍
This ticket was absolutely specific for
@PreserveOnRefresh
. The reason has been identified based on provided code sample and fixed. So this ticket is fixed and closed.If you see another issue then please:
Dialog
repository.Please note that the exception doesn’t identify the ticket. Especially if there is no stackrace. The issue is identified by the steps to reproduce.
This happens for me even without using @PreserveOnRefresh
: this is a clear indicator that this is a totally different issue.