Skip to content

Commit b7e9836

Browse files
committed
Merge branch 'main' into release-next
2 parents 362115a + c164837 commit b7e9836

File tree

8 files changed

+64
-12
lines changed

8 files changed

+64
-12
lines changed

contributors.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- AchThomas
66
- adamdotjs
77
- adil62
8+
- adriananin
89
- adrienharnay
910
- afzalsayed96
1011
- Ajayff4
@@ -71,6 +72,7 @@
7172
- emzoumpo
7273
- engpetermwangi
7374
- ericschn
75+
- faergeek
7476
- FilipJirsak
7577
- frontsideair
7678
- fyzhu
@@ -108,6 +110,7 @@
108110
- janpaepke
109111
- jasikpark
110112
- jasonpaulos
113+
- jb-1980
111114
- jdufresne
112115
- jenseng
113116
- JeraldVin

docs/components/link.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,27 @@ function EditContact() {
9191
}
9292
```
9393

94+
Please note that `relative: "path"` only impacts the resolution of a relative path. It does not change the the "starting" location for that relative path resolution. This resolution is always relative to the current location in the Route hierarchy (i.e., the route `Link` is rendered in).
95+
96+
If you wish to use path-relative routing against the current URL instead of the route hierarchy, you can do that with the current [`location`][use-location] and the `URL` constructor (note the trailing slash behavior):
97+
98+
```js
99+
// Assume the current URL is https://remix.run/docs/en/main/start/quickstart
100+
let location = useLocation();
101+
102+
// Without trailing slashes
103+
new URL(".", window.origin + location.pathname);
104+
// 'https://remix.run/docs/en/main/start/'
105+
new URL("..", window.origin + location.pathname);
106+
// 'https://remix.run/docs/en/main/'
107+
108+
// With trailing slashes:
109+
new URL(".", window.origin + location.pathname + "/");
110+
// 'https://remix.run/docs/en/main/start/future-flags/'
111+
new URL("..", window.origin + location.pathname + "/");
112+
// 'https://remix.run/docs/en/main/start/'
113+
```
114+
94115
## `preventScrollReset`
95116

96117
If you are using [`<ScrollRestoration>`][scrollrestoration], this lets you prevent the scroll position from being reset to the top of the window when the link is clicked.
@@ -205,3 +226,4 @@ function ImageLink(to) {
205226
[picking-a-router]: ../routers/picking-a-router
206227
[navlink]: ./nav-link
207228
[relativesplatpath]: ../hooks/use-resolved-path#splat-paths
229+
[use-location]: ../hooks/use-location

docs/guides/ssr.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const app = express();
6666
let handler = createStaticHandler(routes);
6767

6868
app.get("*", async (req, res) => {
69-
let fetchRequest = createFetchRequest(req);
69+
let fetchRequest = createFetchRequest(req, res);
7070
let context = await handler.query(fetchRequest);
7171

7272
// We'll tackle rendering next...
@@ -81,13 +81,13 @@ const listener = app.listen(3000, () => {
8181
Note we have to first convert the incoming Express request into a Fetch request, which is what the static handler methods operate on. The `createFetchRequest` method is specific to an Express request and in this example is extracted from the `@remix-run/express` adapter:
8282

8383
```js filename=request.js
84-
module.exports = function createFetchRequest(req) {
84+
module.exports = function createFetchRequest(req, res) {
8585
let origin = `${req.protocol}://${req.get("host")}`;
8686
// Note: This had to take originalUrl into account for presumably vite's proxying
8787
let url = new URL(req.originalUrl || req.url, origin);
8888

8989
let controller = new AbortController();
90-
req.on("close", () => controller.abort());
90+
res.on("close", () => controller.abort());
9191

9292
let headers = new Headers();
9393

@@ -121,7 +121,7 @@ Once we've loaded our data by executing all of the matched route loaders for the
121121

122122
```js filename=server.jsx lines=[5-16]
123123
app.get("*", async (req, res) => {
124-
let fetchRequest = createFetchRequest(req);
124+
let fetchRequest = createFetchRequest(req, res);
125125
let context = await handler.query(fetchRequest);
126126

127127
let router = createStaticRouter(
@@ -181,7 +181,7 @@ If any loaders redirect, `handler.query` will return the `Response` directly so
181181

182182
```js filename=server.jsx lines=[5-10]
183183
app.get("*", async (req, res) => {
184-
let fetchRequest = createFetchRequest(req);
184+
let fetchRequest = createFetchRequest(req, res);
185185
let context = await handler.query(fetchRequest);
186186

187187
if (

docs/hooks/use-navigate.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,27 @@ function EditContact() {
9393
}
9494
```
9595

96+
Please note that `relative: "path"` only impacts the resolution of a relative path. It does not change the the "starting" location for that relative path resolution. This resolution is always relative to the current location in the Route hierarchy (i.e., the route `useNavigate` is called in).
97+
98+
If you wish to use path-relative routing against the current URL instead of the route hierarchy, you can do that with the current [`location`][use-location] and the `URL` constructor (note the trailing slash behavior):
99+
100+
```js
101+
// Assume the current URL is https://remix.run/docs/en/main/start/quickstart
102+
let location = useLocation();
103+
104+
// Without trailing slashes
105+
new URL(".", window.origin + location.pathname);
106+
// 'https://remix.run/docs/en/main/start/'
107+
new URL("..", window.origin + location.pathname);
108+
// 'https://remix.run/docs/en/main/'
109+
110+
// With trailing slashes:
111+
new URL(".", window.origin + location.pathname + "/");
112+
// 'https://remix.run/docs/en/main/start/future-flags/'
113+
new URL("..", window.origin + location.pathname + "/");
114+
// 'https://remix.run/docs/en/main/start/'
115+
```
116+
96117
## `options.unstable_flushSync`
97118

98119
The `unstable_flushSync` option tells React Router DOM to wrap the initial state update for this navigation in a [`ReactDOM.flushSync`][flush-sync] call instead of the default [`React.startTransition`][start-transition]. This allows you to perform synchronous DOM actions immediately after the update is flushed to the DOM.

docs/route/loader.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ createBrowserRouter([
4747
]);
4848
```
4949

50-
Note that the `:teamId` in the path is parsed as provided as `params.teamId` by the same name.
50+
Note that the `:teamId` in the path is parsed and provided as `params.teamId` by the same name.
5151

5252
## `request`
5353

docs/start/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ function User() {
419419
}
420420
```
421421

422-
Instead of rending your component, remix will render the nearest [catch boundary][remix-catchboundary] instead.
422+
Instead of rendering your component, remix will render the nearest [catch boundary][remix-catchboundary] instead.
423423

424424
[remix]: https://remix.run
425425
[remix-catchboundary]: https://remix.run/docs/en/v1/api/conventions#catchboundary

examples/ssr-data-router/server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async function createServer() {
5454
}
5555

5656
try {
57-
let appHtml = await render(req);
57+
let appHtml = await render(req, res);
5858
let html = template.replace("<!--app-html-->", appHtml);
5959
res.setHeader("Content-Type", "text/html");
6060
return res.status(200).end(html);

examples/ssr-data-router/src/entry.server.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import {
88
} from "react-router-dom/server";
99
import { routes } from "./App";
1010

11-
export async function render(request: express.Request) {
11+
export async function render(
12+
request: express.Request,
13+
response: express.Response
14+
) {
1215
let { query, dataRoutes } = createStaticHandler(routes);
13-
let remixRequest = createFetchRequest(request);
16+
let remixRequest = createFetchRequest(request, response);
1417
let context = await query(remixRequest);
1518

1619
if (context instanceof Response) {
@@ -29,13 +32,16 @@ export async function render(request: express.Request) {
2932
);
3033
}
3134

32-
export function createFetchRequest(req: express.Request): Request {
35+
export function createFetchRequest(
36+
req: express.Request,
37+
res: express.Response
38+
): Request {
3339
let origin = `${req.protocol}://${req.get("host")}`;
3440
// Note: This had to take originalUrl into account for presumably vite's proxying
3541
let url = new URL(req.originalUrl || req.url, origin);
3642

3743
let controller = new AbortController();
38-
req.on("close", () => controller.abort());
44+
res.on("close", () => controller.abort());
3945

4046
let headers = new Headers();
4147

0 commit comments

Comments
 (0)