Skip to content

Commit a90e8d7

Browse files
vaadin-botcaalador
andauthored
fix: always wait for navigated event for title (#22494) (#22510)
When running with react-router always wait for vaadin-navigated event before updating the title. Fixes #21171 Co-authored-by: caalador <[email protected]>
1 parent 7533a33 commit a90e8d7

File tree

1 file changed

+11
-0
lines changed
  • flow-server/src/main/resources/com/vaadin/flow/server/frontend

1 file changed

+11
-0
lines changed

flow-server/src/main/resources/com/vaadin/flow/server/frontend/Flow.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,11 @@ function useQueuedNavigate(
346346
return enqueueNavigation;
347347
}
348348

349+
const flowNavigation = () => {
350+
// @ts-ignore
351+
window.Vaadin.Flow.navigation = true;
352+
};
353+
349354
function Flow() {
350355
const ref = useRef<HTMLOutputElement>(null);
351356
const navigate = useNavigate();
@@ -403,6 +408,8 @@ function Flow() {
403408
// When navigation is triggered by click on a link, fromAnchor is set to true
404409
// in order to get a server round-trip even when navigating to the same URL again
405410
fromAnchor.current = true;
411+
// @ts-ignore
412+
window.Vaadin.Flow.navigation = true;
406413
navigate(path);
407414
// Dispatch close event for overlay drawer on click navigation.
408415
window.dispatchEvent(new CustomEvent('close-overlay-drawer'));
@@ -463,13 +470,17 @@ function Flow() {
463470
}, [vaadinRouterGoEventHandler, vaadinNavigateEventHandler]);
464471

465472
useEffect(() => {
473+
// @ts-ignore
474+
window.addEventListener("popstate", flowNavigation);
466475
window.addEventListener('click', navigateEventHandler);
467476
flowReact.active = true;
468477

469478
return () => {
470479
containerRef.current?.parentNode?.removeChild(containerRef.current);
471480
containerRef.current?.removeEventListener('flow-portal-add', addPortalEventHandler as EventListener);
472481
containerRef.current = undefined;
482+
// @ts-ignore
483+
window.removeEventListener("popstate", flowNavigation);
473484
window.removeEventListener('click', navigateEventHandler);
474485
flowReact.active = false;
475486
};

0 commit comments

Comments
 (0)