Skip to content

feat: Add Discard popup for browser navigation#4552

Merged
chriskari merged 12 commits intokyma-project:mainfrom
OliwiaGowor:browser-nav-discard
Jan 30, 2026
Merged

feat: Add Discard popup for browser navigation#4552
chriskari merged 12 commits intokyma-project:mainfrom
OliwiaGowor:browser-nav-discard

Conversation

@OliwiaGowor
Copy link
Contributor

@OliwiaGowor OliwiaGowor commented Jan 23, 2026

Description

Changes proposed in this pull request:

  • Add Discard popup for browser navigation
  • Changed <BrowserRouter> to createBrowserRouter and <RouterProvider>

Related issue(s)
Closes #4319

Definition of done

  • The PR's title starts with one of the following prefixes:
    • feat: A new feature
    • fix: A bug fix
    • docs: Documentation only changes
    • refactor: A code change that neither fixes a bug nor adds a feature
    • test: Adding tests
    • revert: Revert commit
    • chore: Maintainance changes to the build process or auxiliary tools, libraries, workflows, etc.
  • Related issues are linked. To link internal trackers, use the issue IDs like backlog#4567
  • Explain clearly why you created the PR and what changes it introduces
  • All necessary steps are delivered, for example, tests, documentation, merging

Comment on lines +11 to +17
const blocker = useBlocker(({ historyAction }) => {
const isBrowserNav = historyAction === 'POP';

return (
isBrowserNav && isResourceEdited.isEdited && formOpen && webNavBlocker
);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every call site of useFormNavigation (about 10+ components) registers a useBlocker with React Router, even though webNavBlocker defaults to false and some of these blockers never actually block. This is relatively harmless but still creates unnecessary overhead.

instead we can implement it like this
const blocker = useBlocker( webNavBlocker ? ({ historyAction }) => { const isBrowserNav = historyAction === 'POP'; return isBrowserNav && isResourceEdited.isEdited && formOpen; } : false, );

Comment on lines +18 to +37
const router = useMemo(
() =>
createBrowserRouter([
{
path: '*',
element: (
<Suspense fallback={<Spinner />}>
<DynamicPageComponent
{...props}
inlineEditForm={
props?.inlineEditForm ? transformedForm : undefined
}
/>
</Suspense>
),
},
// eslint-disable-next-line react-hooks/exhaustive-deps
]),
[props],
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is problematic, useMemo(..., [props]) recreates the router every render because props is a new object reference each time. Recreating the router resets all internal router state (history, blockers, etc.).

@chriskari chriskari merged commit 83de5c9 into kyma-project:main Jan 30, 2026
22 checks passed
@OliwiaGowor OliwiaGowor deleted the browser-nav-discard branch February 20, 2026 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UXC-023 Message Handling - Discard changes

2 participants