Skip to content

Commit bbade81

Browse files
committed
Merge branch 'main' into release-next
2 parents 60af470 + 61ff092 commit bbade81

File tree

8 files changed

+105
-159
lines changed

8 files changed

+105
-159
lines changed

contributors.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- aaronadamsCA
12
- aaronpowell96
23
- aaronshaf
34
- AbePlays
@@ -71,6 +72,7 @@
7172
- atesgoral
7273
- athongsavath
7374
- AustinGil
75+
- avindra
7476
- awthwathje
7577
- axel-habermaier
7678
- baby230211
@@ -176,6 +178,7 @@
176178
- dunglas
177179
- dvargas92495
178180
- dwightwatson
181+
- dwjohnston
179182
- dwt47
180183
- dylanplayer
181184
- eastlondoner
@@ -198,6 +201,7 @@
198201
- evanwinter
199202
- everdimension
200203
- exegeteio
204+
- ezekeal
201205
- F3n67u
202206
- FAL-coffee
203207
- fayez-nazzal
@@ -441,6 +445,7 @@
441445
- marshallwalker
442446
- martensonbj
443447
- marvinwu
448+
- masious
444449
- matchai
445450
- mathieusteele
446451
- matt-l-w
@@ -503,6 +508,7 @@
503508
- n8agrin
504509
- na2hiro
505510
- nareshbhatia
511+
- nathggns
506512
- nauvalazhar
507513
- naveed-fida
508514
- navid-kalaei
@@ -558,6 +564,7 @@
558564
- ptitFicus
559565
- pwbriggs
560566
- pyr0gan
567+
- rachaelmcq
561568
- ramiroazar
562569
- RATIU5
563570
- raulfdm

docs/guides/gotchas.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ if (typeof window === "undefined") {
2020
}
2121
```
2222

23-
This works fine in a Node.js environment, however, Deno actually supports `window`! So if you really want to check whether you're running in the browser, it's better to check for `document` instead:
23+
This works fine in a Node.js environment, however, some environments might actually support `window` (like Deno v1), so if you really want to check whether you're running in the browser, it's better to check for `document` instead:
2424

2525
```ts good
2626
if (typeof document === "undefined") {

docs/guides/mdx.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,12 @@ exports.mdx = async (filename) => {
204204
};
205205
```
206206

207+
The above configuration parses the markdown to insert [highlight.js][highlightjs] friendly DOM elements. To have the syntax highlighting appear, you will also need to include the highlight.js css file. See also [surfacing styles][surfacing-styles].
208+
207209
[mdx-plugin]: https://mdxjs.com/packages/rollup
208210
[mdx]: https://mdxjs.com
209211
[yaml]: https://yaml.org
210212
[mdx-bundler]: https://github.com/kentcdodds/mdx-bundler
211213
[classic-remix-compiler]: ./vite#classic-remix-compiler-vs-remix-vite
214+
[surfacing-styles]: ../styling#surfacing-styles
215+
[highlightjs]: https://highlightjs.org/

docs/hooks/use-fetcher.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ fetcher.submit(
112112

113113
Loads data from a route loader. While multiple nested routes can match a URL, only the leaf route will be called.
114114

115+
Note that when calling `load` on an index route's loader, you must include an [`?index` query param][index-query-param] in order to disambiguate between the `index.tsx` layout and the `root.tsx` route.
116+
115117
```ts
116118
fetcher.load("/some/route");
117119
fetcher.load("/some/route?foo=bar");
@@ -180,3 +182,4 @@ The form method of the submission.
180182
[use-submit]: ./use-submit
181183
[userevalidator]: ./use-revalidator
182184
[shouldrevalidate]: ../route/should-revalidate#shouldrevalidate
185+
[index-query-param]: ../guides/index-query-param

docs/hooks/use-revalidator.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,17 @@ Initiates a revalidation.
4040
```tsx
4141
function useLivePageData() {
4242
const revalidator = useRevalidator();
43-
const interval = useInterval(5000);
4443

45-
useEffect(() => {
44+
useInterval(() => {
4645
if (revalidator.state === "idle") {
4746
revalidator.revalidate();
4847
}
49-
}, [interval, revalidator]);
48+
}, 5000);
5049
}
5150
```
5251

52+
See [here][here] for a sample `useInterval` implementation.
53+
5354
## Notes
5455

5556
While you can render multiple occurrences of `useRevalidator` at the same time, underneath it is a singleton. This means when one `revalidator.revalidate()` is called, all instances go into the `"loading"` state together (or rather, they all update to report the singleton state).
@@ -61,3 +62,4 @@ If a navigation happens while a revalidation is in flight, the revalidation will
6162
[form-component]: ../components/form
6263
[use-fetcher]: ./use-fetcher
6364
[use-submit]: ./use-submit
65+
[here]: https://overreacted.io/making-setinterval-declarative-with-react-hooks

docs/start/quickstart.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ cd my-remix-app
2727
npm init -y
2828
2929
# install runtime dependencies
30-
npm i @remix-run/node @remix-run/react @remix-run/serve isbot@4 react react-dom
30+
npm i @remix-run/node @remix-run/react @remix-run/serve isbot@4 react@18 react-dom@18
3131
3232
# install dev dependencies
3333
npm i -D @remix-run/dev vite
@@ -91,7 +91,16 @@ export default function App() {
9191

9292
## Build and Run
9393

94-
First build the app for production:
94+
First you will need to specify the type as `module` in `package.json` to satisfy esmodule requirements for `remix-run` and future versions of `vite`.
95+
96+
```jsonc filename=package.json lines=[2] nocopy
97+
{
98+
"type": "module"
99+
// ...
100+
}
101+
```
102+
103+
Next build the app for production:
95104

96105
```shellscript nonumber
97106
npx remix vite:build
@@ -101,15 +110,6 @@ You should now see a `build` folder containing a `server` folder (the server ver
101110

102111
👉 **Run the app with `remix-serve`**
103112

104-
First you will need to specify the type in `package.json` as module so that `remix-serve` can run your app.
105-
106-
```jsonc filename=package.json lines=[2] nocopy
107-
{
108-
"type": "module"
109-
// ...
110-
}
111-
```
112-
113113
Now you can run your app with `remix-serve`:
114114

115115
```shellscript nonumber
@@ -139,7 +139,7 @@ Just for kicks, let's stop using `remix-serve` and use express instead.
139139
👉 **Install Express, the Remix Express adapter, and [cross-env] for running in production mode**
140140

141141
```shellscript nonumber
142-
npm i express @remix-run/express cross-env
142+
npm i express@4 @remix-run/express cross-env
143143
144144
# not going to use this anymore
145145
npm uninstall @remix-run/serve

docs/start/tutorial.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,8 @@ There are two APIs we'll be using to load data, [`loader`][loader] and [`useLoad
367367

368368
<docs-info>The following code has a type error in it, we'll fix it in the next section</docs-info>
369369

370-
```tsx filename=app/root.tsx lines=[2,11,15,19-22,25,34-57]
370+
```tsx filename=app/root.tsx lines=[10,14,18-21,24,33-56]
371371
// existing imports
372-
import { json } from "@remix-run/node";
373372
import {
374373
Form,
375374
Link,
@@ -388,7 +387,7 @@ import { getContacts } from "./data";
388387

389388
export const loader = async () => {
390389
const contacts = await getContacts();
391-
return json({ contacts });
390+
return { contacts };
392391
};
393392

394393
export default function App() {
@@ -470,16 +469,15 @@ These params are most often used to find a record by ID. Let's try it out.
470469

471470
<docs-info>The following code has type errors in it, we'll fix them in the next section</docs-info>
472471

473-
```tsx filename=app/routes/contacts.$contactId.tsx lines=[1-2,5,7-10,13]
474-
import { json } from "@remix-run/node";
472+
```tsx filename=app/routes/contacts.$contactId.tsx lines=[1,4,6-9,12]
475473
import { Form, useLoaderData } from "@remix-run/react";
476474
// existing imports
477475

478476
import { getContact } from "../data";
479477

480478
export const loader = async ({ params }) => {
481479
const contact = await getContact(params.contactId);
482-
return json({ contact });
480+
return { contact };
483481
};
484482

485483
export default function Contact() {
@@ -509,7 +507,7 @@ export const loader = async ({
509507
}: LoaderFunctionArgs) => {
510508
invariant(params.contactId, "Missing contactId param");
511509
const contact = await getContact(params.contactId);
512-
return json({ contact });
510+
return { contact };
513511
};
514512

515513
// existing code
@@ -532,7 +530,7 @@ export const loader = async ({
532530
if (!contact) {
533531
throw new Response("Not Found", { status: 404 });
534532
}
535-
return json({ contact });
533+
return { contact };
536534
};
537535

538536
// existing code
@@ -569,7 +567,7 @@ import { createEmptyContact, getContacts } from "./data";
569567

570568
export const action = async () => {
571569
const contact = await createEmptyContact();
572-
return json({ contact });
570+
return { contact };
573571
};
574572

575573
// existing code
@@ -611,7 +609,6 @@ Nothing we haven't seen before, feel free to copy/paste:
611609

612610
```tsx filename=app/routes/contacts.$contactId_.edit.tsx
613611
import type { LoaderFunctionArgs } from "@remix-run/node";
614-
import { json } from "@remix-run/node";
615612
import { Form, useLoaderData } from "@remix-run/react";
616613
import invariant from "tiny-invariant";
617614

@@ -625,7 +622,7 @@ export const loader = async ({
625622
if (!contact) {
626623
throw new Response("Not Found", { status: 404 });
627624
}
628-
return json({ contact });
625+
return { contact };
629626
};
630627

631628
export default function EditContact() {
@@ -701,7 +698,7 @@ import type {
701698
ActionFunctionArgs,
702699
LoaderFunctionArgs,
703700
} from "@remix-run/node";
704-
import { json, redirect } from "@remix-run/node";
701+
import { redirect } from "@remix-run/node";
705702
// existing imports
706703

707704
import { getContact, updateContact } from "../data";
@@ -797,7 +794,7 @@ Now that we know how to redirect, let's update the action that creates new conta
797794

798795
```tsx filename=app/root.tsx lines=[2,7]
799796
// existing imports
800-
import { json, redirect } from "@remix-run/node";
797+
import { redirect } from "@remix-run/node";
801798
// existing imports
802799

803800
export const action = async () => {
@@ -1107,7 +1104,7 @@ export const loader = async ({
11071104
const url = new URL(request.url);
11081105
const q = url.searchParams.get("q");
11091106
const contacts = await getContacts(q);
1110-
return json({ contacts });
1107+
return { contacts };
11111108
};
11121109

11131110
// existing code
@@ -1141,7 +1138,7 @@ export const loader = async ({
11411138
const url = new URL(request.url);
11421139
const q = url.searchParams.get("q");
11431140
const contacts = await getContacts(q);
1144-
return json({ contacts, q });
1141+
return { contacts, q };
11451142
};
11461143

11471144
export default function App() {
@@ -1213,22 +1210,25 @@ You could certainly do this as a controlled component. You will have more synchr
12131210
<summary>Expand this to see what it would look like</summary>
12141211

12151212
```tsx filename=app/root.tsx lines=[2,9-10,12-16,30-33,36-37]
1216-
// existing imports
1217-
import { useEffect, useState } from "react";
1213+
// We no longer need useEffect
1214+
import { useState } from "react";
12181215

12191216
// existing imports & exports
12201217

12211218
export default function App() {
12221219
const { contacts, q } = useLoaderData<typeof loader>();
12231220
const navigation = useNavigation();
12241221
// the query now needs to be kept in state
1222+
const [prevQ, setPrevQ] = useState(q);
12251223
const [query, setQuery] = useState(q || "");
12261224

1227-
// we still have a `useEffect` to synchronize the query
1228-
// to the component state on back/forward button clicks
1229-
useEffect(() => {
1225+
// We can avoid using `useEffect` to synchronize the query
1226+
// by using a separate piece of state to store the previous
1227+
// value
1228+
if (q !== prevQ) {
1229+
setPrevQ(q);
12301230
setQuery(q || "");
1231-
}, [q]);
1231+
}
12321232

12331233
return (
12341234
<html lang="en">

0 commit comments

Comments
 (0)