Skip to content

Commit

Permalink
Merge branch 'release-next'
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed May 17, 2023
2 parents c5b086a + 0815c96 commit f397ad7
Show file tree
Hide file tree
Showing 16 changed files with 316 additions and 31 deletions.
8 changes: 8 additions & 0 deletions packages/react-router-dom-v5-compat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `react-router-dom-v5-compat`

## 6.11.2

### Patch Changes

- Updated dependencies:
- `react-router@6.11.2`
- `react-router-dom@6.11.2`

## 6.11.1

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router-dom-v5-compat/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router-dom-v5-compat",
"version": "6.11.1",
"version": "6.11.2",
"description": "Migration path to React Router v6 from v4/5",
"keywords": [
"react",
Expand All @@ -24,7 +24,7 @@
"types": "./dist/index.d.ts",
"dependencies": {
"history": "^5.3.0",
"react-router": "6.11.1"
"react-router": "6.11.2"
},
"peerDependencies": {
"react": ">=16.8",
Expand Down
9 changes: 9 additions & 0 deletions packages/react-router-dom/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# `react-router-dom`

## 6.11.2

### Patch Changes

- Export `SetURLSearchParams` type ([#10444](https://github.com/remix-run/react-router/pull/10444))
- Updated dependencies:
- `react-router@6.11.2`
- `@remix-run/router@1.6.2`

## 6.11.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-dom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ export function useSearchParams(
return [searchParams, setSearchParams];
}

type SetURLSearchParams = (
export type SetURLSearchParams = (
nextInit?:
| URLSearchParamsInit
| ((prev: URLSearchParams) => URLSearchParamsInit),
Expand Down
6 changes: 3 additions & 3 deletions packages/react-router-dom/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router-dom",
"version": "6.11.1",
"version": "6.11.2",
"description": "Declarative routing for React web applications",
"keywords": [
"react",
Expand All @@ -23,8 +23,8 @@
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"@remix-run/router": "1.6.1",
"react-router": "6.11.1"
"@remix-run/router": "1.6.2",
"react-router": "6.11.2"
},
"devDependencies": {
"react": "^18.2.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router-native/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `react-router-native`

## 6.11.2

### Patch Changes

- Export `SetURLSearchParams` type ([#10444](https://github.com/remix-run/react-router/pull/10444))
- Updated dependencies:
- `react-router@6.11.2`

## 6.11.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/react-router-native/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function useSearchParams(
return [searchParams, setSearchParams];
}

type SetURLSearchParams = (
export type SetURLSearchParams = (
nextInit?:
| URLSearchParamsInit
| ((prev: URLSearchParams) => URLSearchParamsInit),
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router-native",
"version": "6.11.1",
"version": "6.11.2",
"description": "Declarative routing for React Native applications",
"keywords": [
"react",
Expand All @@ -22,7 +22,7 @@
"types": "./dist/index.d.ts",
"dependencies": {
"@ungap/url-search-params": "^0.1.4",
"react-router": "6.11.1"
"react-router": "6.11.2"
},
"devDependencies": {
"react": "^18.2.0",
Expand Down
8 changes: 8 additions & 0 deletions packages/react-router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# `react-router`

## 6.11.2

### Patch Changes

- Fix `basename` duplication in descendant `<Routes>` inside a `<RouterProvider>` ([#10492](https://github.com/remix-run/react-router/pull/10492))
- Updated dependencies:
- `@remix-run/router@1.6.2`

## 6.11.1

### Patch Changes
Expand Down
175 changes: 175 additions & 0 deletions packages/react-router/__tests__/useNavigate-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,181 @@ describe("useNavigate", () => {
`);
});
});

describe("with a basename", () => {
describe("in a MemoryRouter", () => {
it("in a root route", () => {
let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(
<MemoryRouter basename="/base" initialEntries={["/base"]}>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/path" element={<h1>Path</h1>} />
</Routes>
</MemoryRouter>
);
});

function Home() {
let navigate = useNavigate();
return <button onClick={() => navigate("/path")} />;
}

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<button
onClick={[Function]}
/>
`);

// @ts-expect-error
let button = renderer.root.findByType("button");
TestRenderer.act(() => button.props.onClick());

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<h1>
Path
</h1>
`);
});

it("in a descendant route", () => {
let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(
<MemoryRouter basename="/base" initialEntries={["/base"]}>
<Routes>
<Route
path="/*"
element={
<Routes>
<Route index element={<Home />} />
</Routes>
}
/>
<Route path="/path" element={<h1>Path</h1>} />
</Routes>
</MemoryRouter>
);
});

function Home() {
let navigate = useNavigate();
return <button onClick={() => navigate("/path")} />;
}

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<button
onClick={[Function]}
/>
`);

// @ts-expect-error
let button = renderer.root.findByType("button");
TestRenderer.act(() => button.props.onClick());

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<h1>
Path
</h1>
`);
});
});

describe("in a RouterProvider", () => {
it("in a root route", () => {
let router = createMemoryRouter(
[
{
path: "/",
Component: Home,
},
{ path: "/path", Component: () => <h1>Path</h1> },
],
{ basename: "/base", initialEntries: ["/base"] }
);

function Home() {
let navigate = useNavigate();
return <button onClick={() => navigate("/path")} />;
}

let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(<RouterProvider router={router} />);
});

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<button
onClick={[Function]}
/>
`);

// @ts-expect-error
let button = renderer.root.findByType("button");
TestRenderer.act(() => button.props.onClick());

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<h1>
Path
</h1>
`);
});

it("in a descendant route", () => {
let router = createMemoryRouter(
[
{
path: "/*",
Component() {
return (
<Routes>
<Route index element={<Home />} />
</Routes>
);
},
},
{ path: "/path", Component: () => <h1>Path</h1> },
],
{ basename: "/base", initialEntries: ["/base"] }
);

function Home() {
let navigate = useNavigate();
return <button onClick={() => navigate("/path")} />;
}

let renderer: TestRenderer.ReactTestRenderer;
TestRenderer.act(() => {
renderer = TestRenderer.create(<RouterProvider router={router} />);
});

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<button
onClick={[Function]}
/>
`);

// @ts-expect-error
let button = renderer.root.findByType("button");
TestRenderer.act(() => button.props.onClick());

// @ts-expect-error
expect(renderer.toJSON()).toMatchInlineSnapshot(`
<h1>
Path
</h1>
`);
});
});
});
});

function UseNavigateButton({
Expand Down
19 changes: 14 additions & 5 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function useNavigateUnstable(): NavigateFunction {
`useNavigate() may be used only in the context of a <Router> component.`
);

let dataRouterContext = React.useContext(DataRouterContext);
let { basename, navigator } = React.useContext(NavigationContext);
let { matches } = React.useContext(RouteContext);
let { pathname: locationPathname } = useLocation();
Expand Down Expand Up @@ -222,10 +223,12 @@ function useNavigateUnstable(): NavigateFunction {
);

// If we're operating within a basename, prepend it to the pathname prior
// to handing off to history. If this is a root navigation, then we
// navigate to the raw basename which allows the basename to have full
// control over the presence of a trailing slash on root links
if (basename !== "/") {
// to handing off to history (but only if we're not in a data router,
// otherwise it'll prepend the basename inside of the router).
// If this is a root navigation, then we navigate to the raw basename
// which allows the basename to have full control over the presence of a
// trailing slash on root links
if (dataRouterContext == null && basename !== "/") {
path.pathname =
path.pathname === "/"
? basename
Expand All @@ -238,7 +241,13 @@ function useNavigateUnstable(): NavigateFunction {
options
);
},
[basename, navigator, routePathnamesJson, locationPathname]
[
basename,
navigator,
routePathnamesJson,
locationPathname,
dataRouterContext,
]
);

return navigate;
Expand Down
4 changes: 2 additions & 2 deletions packages/react-router/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-router",
"version": "6.11.1",
"version": "6.11.2",
"description": "Declarative routing for React",
"keywords": [
"react",
Expand All @@ -23,7 +23,7 @@
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"dependencies": {
"@remix-run/router": "1.6.1"
"@remix-run/router": "1.6.2"
},
"devDependencies": {
"react": "^18.2.0"
Expand Down
7 changes: 7 additions & 0 deletions packages/router/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# `@remix-run/router`

## 1.6.2

### Patch Changes

- Fix HMR-driven error boundaries by properly reconstructing new routes and `manifest` in `\_internalSetRoutes` ([#10437](https://github.com/remix-run/react-router/pull/10437))
- Fix bug where initial data load would not kick off when hash is present ([#10493](https://github.com/remix-run/react-router/pull/10493))

## 1.6.1

### Patch Changes
Expand Down

0 comments on commit f397ad7

Please sign in to comment.