-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Closed as not planned
Labels
Description
Reproduction
stackblitz: https://stackblitz.com/~/github.com/issues-repros/react-router-overlay-repro
github repo: https://github.com/issues-repros/react-router-overlay-repro
System Info
System:
OS: macOS 15.4.1
CPU: (10) arm64 Apple M1 Pro
Memory: 89.34 MB / 16.00 GB
Shell: 4.0.0 - /opt/homebrew/bin/fish
Binaries:
Node: 23.11.0 - /opt/homebrew/bin/node
npm: 10.9.2 - /opt/homebrew/bin/npm
pnpm: 10.10.0 - /opt/homebrew/bin/pnpm
bun: 1.2.6 - ~/.bun/bin/bun
Browsers:
Chrome: 140.0.7339.133
Safari: 18.4
npmPackages:
react-router: ^7.9.1 => 7.9.1
vite: ^7.1.2 => 7.1.5Used Package Manager
pnpm
Expected Behavior
const Params = () => {
const params = useParams()
const context = useContext(NumberContext)
return (
<section>
<h3>params:</h3>
<pre>{JSON.stringify({ params, context }, null, 2)}</pre>
</section>
)
}
const router = createBrowserRouter([
{
path: ":id",
Component: () => (
<div>
<h1>:id</h1>
<Params />
<Button
type="primary"
onClick={() =>
overlay.open(({ isOpen, close }) => (
<Drawer title="Basic Drawer" open={isOpen} onClose={close}>
<Params />
</Drawer>
))}
>
Open Drawer
</Button>
</div>
),
},
])useParams inside drawer works correctly
Actual Behavior
useParams value inside drawer is empty, unlike context value.
Workaround
while manually injecting RouteContext works, it's not really feasible as this workaround requires useContext and our project has hundreds of existing overlay.open patterns being used without hooks.
import { UNSAFE_RouteContext as RouteContext } from "react-router"
const Page = () => {
const context = useContext(RouteContext)
return (
<Button
type="primary"
onClick={() =>
overlay.open(({ isOpen, close }) => (
<RouteContext.Provider value={context}>
<Drawer title="Basic Drawer" open={isOpen} onClose={close}>
<Params />
</Drawer>
</RouteContext.Provider>
))}
>
Open Drawer
</Button>
)
}