-
Notifications
You must be signed in to change notification settings - Fork 176
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
Strange behavior with History -> replaceState(state,location) when react is enabled #19580
Comments
Looks like a bug in Flow/React Router integration that is new in 24.4. |
ReplaceState requires the origin to be the same as for the current URL so the usual way is to just give the replaced part e.g. Also instead of going through the extra roundtrip to the client with
The direct call to the browser |
We have another problem that may be related to this one: We have a component with a route that implements BeforeLeaveObserver. Within this component we call replaceState on the history. With the legacy Vaddin router the beforeLeave method is not called on the component whereas it is called with the React router. @Route(value = "test/:child?")
public class TestView extends VerticalLayout implements BeforeEnterObserver, BeforeLeaveObserver {
public TestView() {
add(new Button("Replace history state", click -> updatePathWithSelectedChild("child2")));
}
@Override
public void beforeEnter(BeforeEnterEvent event) {
add(new NativeLabel("beforeEnter Called"));
}
@Override
public void beforeLeave(BeforeLeaveEvent beforeLeaveEvent) {
add(new NativeLabel("beforeLeave Called"));
}
private void updatePathWithSelectedChild(String child) {
var page = UI.getCurrent().getPage();
page.fetchCurrentURL(url -> page.getHistory().replaceState(null, buildNewLocation(url, child)));
}
private Location buildNewLocation(URL url, String child) {
var path = url.getPath();
path = path.substring(path.indexOf("/test"), path.lastIndexOf("/") + 1) + child;
return new Location(path);
}
} Yet another difference: With the React router the URL is updated accordingly, with the legacy Vaadin router not! |
@stefanbrenner thanks for your comment. Could you please make a new ticket for the described case. It would be easier to track these issues separately. |
see #19613 |
The history.replaceState() invocation is still resulting in invalid url. Issue still exists in the latest vaadin 24.4.12 release |
Faced an issue that maybe related. In my project it looks like simple url parameters don't work unless disabling react (router). Didn't yet reduce a case, but this seems very critical to me. My app is bit not trivial though regarding routing, it dynamically registers routes (for reasons...). Example from a view:
Registering view:
This vaadin-maven-plugin configuration is a workaround (well, makes the client bundle smallers so maybe best to keep it on anyways):
|
@mstahv If you could get a simple sample that doesn't work for the url parameters. |
Fix navigating with full url for instance when adding a query parameter at the end. Fixes #19580
Fix navigating with full url for instance when adding a query parameter at the end. Fixes #19580
Fix navigating with full url for instance when adding a query parameter at the end. Fixes #19580
Fix navigating with full url for instance when adding a query parameter at the end. Fixes #19580 Co-authored-by: caalador <[email protected]>
This ticket/PR has been released with Vaadin 24.7.0.alpha5 and is also targeting the upcoming stable 24.7.0 version. |
This ticket/PR has been released with Vaadin 24.6.3. |
Description of the bug
Since update to Vaadin 24.4.1 there is a strange behavoir when using replaceState() in History class. If I use the method to update the displayed URL (eg. history.replaceState(null,"http://localhost:8080/?test=test") , it results in opening the invalid url http://localhost:8080/http://localhost:8080/?test=test. If I set react.enabled=false, then it works as expected.
Expected behavior
Browser shows expected URL after history.replaceState call.
Minimal reproducible example
Use any Vaadin 24.4.1 project (eg. skeleton-starter-flow-spring.24).
Call method for updating url parameter, eg:
with:
Versions
The text was updated successfully, but these errors were encountered: