Skip to content

fix(react-router): forward NavigateOptions through RouterProvider's navigator - #15781

Merged
brophdawg11 merged 3 commits into
remix-run:mainfrom
adityajai119:fix/router-provider-navigator-options
Nov 19, 2026
Merged

brophdawg11 merged 3 commits into
remix-run:mainfrom
adityajai119:fix/router-provider-navigator-options

Conversation

@adityajai119

Copy link
Copy Markdown
Contributor

Fixes #15780

Inside a descendant <Routes> rendered under <RouterProvider> (or <HydratedRouter> in Framework Mode), IsDataRouteContext is false, so useNavigate() (used by <Link>, <NavLink>, and useSearchParams()) calls useNavigateUnstable(), which invokes navigator.push(path, options.state, options) or navigator.replace(path, options.state, options).

<RouterProvider>'s navigator in packages/react-router/lib/components.tsx only forwarded state and preventScrollReset:

push: (to, state, opts) =>
  router.navigate(to, {
    state,
    preventScrollReset: opts?.preventScrollReset,
  }),
replace: (to, state, opts) =>
  router.navigate(to, {
    replace: true,
    state,
    preventScrollReset: opts?.preventScrollReset,
  }),

so mask, defaultShouldRevalidate, flushSync, viewTransition, and relative were dropped. For example, <Link to="/gallery?photo=1" mask="/images/1"> inside a descendant <Routes> rendered <a href="/images/1">, yet clicking it left location.mask as undefined and navigated the URL bar to /gallery?photo=1, and defaultShouldRevalidate={false} still revalidated active data route loaders.

This spreads opts into router.navigate(to, ...) while preserving replace (opts?.replace === false ? false : undefined for push, true for replace) and giving an explicit state argument precedence when defined:

push: (to, state, opts) =>
  router.navigate(to, {
    ...opts,
    replace: opts?.replace === false ? false : undefined,
    state: state !== undefined ? state : opts?.state,
  }),
replace: (to, state, opts) =>
  router.navigate(to, {
    ...opts,
    replace: true,
    state: state !== undefined ? state : opts?.state,
  }),

Tests: new unit test in packages/react-router/__tests__/dom/data-browser-router-test.tsx (runs under both <DataBrowserRouter> and <DataHashRouter>), verifying defaultShouldRevalidate: false, mask, flushSync, and viewTransition across <Link> and useNavigate({ replace: true }) inside a descendant <Routes>. Fails on main:

Expected: 0
Received: 1
Tests: 2 failed, 345 skipped, 347 total

and passes with this change. Also run locally on Windows 11 with Node 24.22.1:

  • pnpm test packages/react-router/__tests__/dom/data-browser-router-test.tsx packages/react-router/__tests__/descendant-routes-splat-matching-test.tsx packages/react-router/__tests__/descendant-routes-params-test.tsx: 3 suites, 355 passed
  • npx tsc --noEmit in packages/react-router: clean
  • pnpm exec eslint and pnpm exec prettier --check on changed files: clean
  • pnpm changes:validate: valid
  • pnpm run --filter react-router build and the standalone script from <RouterProvider> drops mask, defaultShouldRevalidate, flushSync, and viewTransition for navigations inside descendant <Routes> #15780 against dist/production/index.js: loaderCalls stays 0, location.mask and window.location.pathname match /images/1 and /images/2, and flushSync and startViewTransition are called

AI-assisted: drafted with an AI coding agent; the tests above were run locally.

…avigator

Inside descendant <Routes> under <RouterProvider>, useNavigate() uses
useNavigateUnstable(), which calls navigator.push(path, options.state,
options) and navigator.replace(path, options.state, options).
RouterProvider's navigator only forwarded state and preventScrollReset,
dropping mask, defaultShouldRevalidate, flushSync, viewTransition, and
relative.

Forward opts to router.navigate() while keeping push/replace semantics
and explicit state arguments intact.

Fixes remix-run#15780
Cover useSearchParams forwarding and navigator history/state precedence, and clarify the release note.

@brophdawg11 brophdawg11 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed head 89156cbe0ce00a81dca6efa08a91894048558366 after the main update. The scoped patch matches the previously reviewed fix and standalone regressions; I rechecked its interaction with the updated navigation callers and router validation. No blocking findings. Merge remains gated on current-head CI.

Authored by an AI agent on behalf of @brophdawg11

@brophdawg11
brophdawg11 merged commit 59a272b into remix-run:main Nov 19, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<RouterProvider> drops mask, defaultShouldRevalidate, flushSync, and viewTransition for navigations inside descendant <Routes>

2 participants