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

fix: render React layout on Flow -> Flow navigation #19084

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
953bb60
fix: render React layout on Flow -> Flow navigation
platosha Apr 3, 2024
ff22fec
Merge branch 'main' into fix/ap/react-layout-update
platosha May 15, 2024
294f409
fix: make NavigationIT pass
platosha May 17, 2024
6f82796
Merge branch 'main' into fix/ap/react-layout-update
platosha May 17, 2024
13d3ff5
fix refresh tests
platosha May 17, 2024
ab6a045
Merge branch 'main' into fix/ap/react-layout-update
platosha May 17, 2024
4cc9f2f
Merge branch 'main' into fix/ap/react-layout-update
mshabarov May 28, 2024
acc581d
server to server navigation should use onBeforeEnter
caalador May 28, 2024
656bfaf
Remove unneeded continue block
caalador May 28, 2024
5ae4212
useState to not call onBefore twice
caalador May 29, 2024
dfff3ef
proceed on continue
caalador May 29, 2024
c7aa1ee
Ignore blocker for non react history navigation
caalador May 30, 2024
eb6883c
format
caalador May 30, 2024
edaaf16
Remove invoking popstate 'vaadin-router-ignore' when React router is …
platosha May 30, 2024
1f056bf
Revert "Remove invoking popstate 'vaadin-router-ignore' when React ro…
caalador May 31, 2024
5c88737
Don't fire popstate for updating trimmed route.
caalador May 31, 2024
a8cb209
more fix for the history
mshabarov May 31, 2024
a306aa5
chore: fix url in vaadinNavigateEventHandler
tltv May 31, 2024
f4aff77
Fix junit tests
caalador May 31, 2024
3baa269
chore: fix compilation error
tltv May 31, 2024
bca440d
Use a base path for the router
Artur- May 31, 2024
58c00ca
use switch for push and pop, ignore history test partially
mshabarov May 31, 2024
8146f55
Push two states before going back to avoid returning to the original …
Artur- May 31, 2024
471aecc
Do not proceed with client side navigation if the server side forward…
Artur- May 31, 2024
d701057
But first navigation must proceed...uh
Artur- May 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions flow-server/src/main/java/com/vaadin/flow/component/UI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1694,6 +1694,7 @@ public List<HasElement> getActiveRouterTargetsChain() {
private boolean navigationInProgress = false;

private String forwardToClientUrl = null;
private boolean serverForwarded = false;

private boolean firstNavigation = true;

Expand Down Expand Up @@ -1847,9 +1848,13 @@ public void browserNavigate(BrowserNavigateEvent event) {
} else if (isPostponed()) {
serverPaused();
} else {
// acknowledge client, but cancel if session not open
serverConnected(
!getSession().getState().equals(VaadinSessionState.OPEN));
if (!firstNavigation && serverForwarded) {
cancelClient();
} else {
// acknowledge client, but cancel if session not open
serverConnected(!getSession().getState()
.equals(VaadinSessionState.OPEN));
}
replaceStateIfDiffersAndNoReplacePending(event.route, location);
}
}
Expand All @@ -1869,11 +1874,18 @@ private void replaceStateIfDiffersAndNoReplacePending(String route,
.containsPendingJavascript("window.history.replaceState")) {
// See InternalRedirectHandler invoked via Router.
getPage().getHistory().replaceState(null, location);
// getPage().executeJs(
// "setTimeout(() => { window.history.replaceState($0, '', $1);})",
// null,
// Optional.ofNullable(location)
// .map(Location::getPathWithQueryParameters)
// .map(path -> path.isEmpty() ? "." : path)
// .orElse(null));
}
}

/**
* Check that the view can be leave. This method is invoked when the client
* Check that the view can be left. This method is invoked when the client
* router tries to navigate to a client route while the current route is a
* server route.
* <p>
Expand Down Expand Up @@ -2000,7 +2012,7 @@ private void handleNavigation(Location location,

forwardToClientUrl = clientNavigationStateRenderer
.getClientForwardRoute();

serverForwarded = clientNavigationStateRenderer.isServerForwarded();
adjustPageTitle();

} catch (Exception exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class JavaScriptNavigationStateRenderer extends NavigationStateRenderer {
static final String NOT_SUPPORT_REROUTE = "BeforeEvent.rerouteTo() with a client side route is not supported";

private String clientForwardRoute;
private boolean serverForwarded = false;

private ContinueNavigationAction continueNavigationAction;

Expand All @@ -69,6 +70,15 @@ public String getClientForwardRoute() {
return clientForwardRoute;
}

/**
* Gets the server forwarded flag.
*
* @return the server forwarded flag.
*/
public boolean isServerForwarded() {
return serverForwarded;
}

@Override
public int handle(NavigationEvent event) {

Expand All @@ -90,6 +100,9 @@ protected Optional<Integer> handleTriggeredBeforeEvent(
clientForwardRoute = beforeEvent.getUnknownForward();
return Optional.of(HttpStatusCode.OK.getCode());
}
} else if (beforeEvent.hasForwardTarget()) {
// Forwarded to another route, e.g. a login view
serverForwarded = true;
}

if (beforeEvent.hasUnknownReroute()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,10 @@ public void pushState(JsonValue state, Location location) {
location);
// Second parameter is title which is currently ignored according to
// https://developer.mozilla.org/en-US/docs/Web/API/History_API
ui.getPage().executeJs(
"setTimeout(() => { window.history.pushState($0, '', $1); window.dispatchEvent(new PopStateEvent('popstate', {state: 'vaadin-router-ignore'})); })",
state, pathWithQueryParameters);
final String pushStateScript = ui.getSession().getConfiguration()
.isReactEnabled() ? "window.history.pushState($0, '', $1);"
: "setTimeout(() => { window.history.pushState($0, '', $1); window.dispatchEvent(new PopStateEvent('popstate', {state: 'vaadin-router-ignore'})); })";
ui.getPage().executeJs(pushStateScript, state, pathWithQueryParameters);
}

/**
Expand Down Expand Up @@ -225,9 +226,11 @@ public void replaceState(JsonValue state, Location location) {
location);
// Second parameter is title which is currently ignored according to
// https://developer.mozilla.org/en-US/docs/Web/API/History_API
ui.getPage().executeJs(
"setTimeout(() => { window.history.replaceState($0, '', $1); window.dispatchEvent(new PopStateEvent('popstate', {state: 'vaadin-router-ignore'})); })",
state, pathWithQueryParameters);
final String replaceStateScript = ui.getSession().getConfiguration()
.isReactEnabled() ? "window.history.replaceState($0, '', $1);"
: "setTimeout(() => { window.history.replaceState($0, '', $1); window.dispatchEvent(new PopStateEvent('popstate', {state: 'vaadin-router-ignore'})); })";
ui.getPage().executeJs(replaceStateScript, state,
pathWithQueryParameters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ public void proceed() {
event.getLocation(), event.getUI(),
NavigationTrigger.PROGRAMMATIC);
}

final UI ui = event.getUI();
handler.handle(event);
if (ui.getSession().getConfiguration().isReactEnabled()) {
ui.getInternals().clearLastHandledNavigation();
}
setReferences(null, null);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,21 @@ private void pushHistoryStateIfNeeded(NavigationEvent event, UI ui) {
.getPathWithQueryParameters()))) {

if (shouldPushHistoryState(event)) {
pushHistoryState(event);
if (ui.getSession().getConfiguration().isReactEnabled()) {
ui.getPage().executeJs(
"setTimeout(() => { window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { url: $0 } })); })",
event.getLocation().getPathWithQueryParameters());
} else {
pushHistoryState(event);
}
}

ui.getInternals().setLastHandledNavigation(event.getLocation());
} else if (ui.getInternals().getSession().getConfiguration()
.isReactEnabled()) {
} else if (ui.getSession().getConfiguration().isReactEnabled()) {
if (shouldPushHistoryState(event)) {
pushHistoryState(event);
ui.getPage().executeJs(
"setTimeout(() => { window.dispatchEvent(new CustomEvent('vaadin-navigate', { detail: { url: $0 } })); })",
event.getLocation().getPathWithQueryParameters());
}
}
}
Expand Down
Loading
Loading