Skip to content

Commit cac3a94

Browse files
Merge pull request #1 from reactjs/main
Sync with react.dev @ e07ac94 (#481)
2 parents abf109a + 7fa3d31 commit cac3a94

17 files changed

+104
-0
lines changed

scripts/deadLinkChecker.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ const fileCache = new Map();
1111
const anchorMap = new Map(); // Map<filepath, Set<anchorId>>
1212
const contributorMap = new Map(); // Map<anchorId, URL>
1313
<<<<<<< HEAD
14+
<<<<<<< HEAD
15+
=======
16+
const redirectMap = new Map(); // Map<source, destination>
17+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
1418
=======
1519
const redirectMap = new Map(); // Map<source, destination>
1620
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
@@ -167,7 +171,10 @@ async function validateLink(link) {
167171
}
168172

169173
<<<<<<< HEAD
174+
<<<<<<< HEAD
175+
=======
170176
=======
177+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
171178
// Check for redirects
172179
if (redirectMap.has(urlWithoutAnchor)) {
173180
const redirectDestination = redirectMap.get(urlWithoutAnchor);
@@ -184,6 +191,9 @@ async function validateLink(link) {
184191
return validateLink(redirectedLink);
185192
}
186193

194+
<<<<<<< HEAD
195+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
196+
=======
187197
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
188198
// Check if it's an error code link
189199
const errorCodeMatch = urlWithoutAnchor.match(/^\/errors\/(\d+)$/);
@@ -318,8 +328,12 @@ async function fetchErrorCodes() {
318328
}
319329
const codes = await response.json();
320330
errorCodes = new Set(Object.keys(codes));
331+
<<<<<<< HEAD
321332
<<<<<<< HEAD
322333
console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes\n`));
334+
=======
335+
console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes`));
336+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
323337
=======
324338
console.log(chalk.gray(`Fetched ${errorCodes.size} React error codes`));
325339
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
@@ -329,7 +343,10 @@ async function fetchErrorCodes() {
329343
}
330344

331345
<<<<<<< HEAD
346+
<<<<<<< HEAD
347+
=======
332348
=======
349+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
333350
async function buildRedirectsMap() {
334351
try {
335352
const vercelConfigPath = path.join(__dirname, '../vercel.json');
@@ -354,13 +371,20 @@ async function buildRedirectsMap() {
354371
}
355372
}
356373

374+
<<<<<<< HEAD
375+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
376+
=======
357377
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
358378
async function main() {
359379
const files = getMarkdownFiles();
360380
console.log(chalk.gray(`Checking ${files.length} markdown files...`));
361381

362382
await fetchErrorCodes();
363383
<<<<<<< HEAD
384+
<<<<<<< HEAD
385+
=======
386+
await buildRedirectsMap();
387+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
364388
=======
365389
await buildRedirectsMap();
366390
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
@@ -374,6 +398,10 @@ async function main() {
374398

375399
if (deadLinks.length > 0) {
376400
<<<<<<< HEAD
401+
<<<<<<< HEAD
402+
=======
403+
console.log('\n');
404+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
377405
=======
378406
console.log('\n');
379407
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9

src/content/learn/add-react-to-an-existing-project.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ Here's how we recommend to set it up:
2424
2. **Specify `/some-app` as the *base path*** in your framework's configuration (here's how: [Next.js](https://nextjs.org/docs/app/api-reference/config/next-config-js/basePath), [Gatsby](https://www.gatsbyjs.com/docs/how-to/previews-deploys-hosting/path-prefix/)).
2525
3. **Configure your server or a proxy** so that all requests under `/some-app/` are handled by your React app.
2626

27+
<<<<<<< HEAD
2728
<<<<<<< HEAD
2829
This ensures the React part of your app can [benefit from the best practices](/learn/creating-a-react-app#full-stack-frameworks) baked into those frameworks.
2930
=======
3031
This ensures the React part of your app can [benefit from the best practices](/learn/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks.
3132
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
33+
=======
34+
This ensures the React part of your app can [benefit from the best practices](/learn/build-a-react-app-from-scratch#consider-using-a-framework) baked into those frameworks.
35+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
3236
3337
Many React-based frameworks are full-stack and let your React app take advantage of the server. However, you can use the same approach even if you can't or don't want to run JavaScript on the server. In that case, serve the HTML/CSS/JS export ([`next export` output](https://nextjs.org/docs/advanced-features/static-html-export) for Next.js, default for Gatsby) at `/some-app/` instead.
3438

src/content/learn/synchronizing-with-effects.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,15 @@ Writing `fetch` calls inside Effects is a [popular way to fetch data](https://ww
732732
733733
This list of downsides is not specific to React. It applies to fetching data on mount with any library. Like with routing, data fetching is not trivial to do well, so we recommend the following approaches:
734734
735+
<<<<<<< HEAD
735736
<<<<<<< HEAD
736737
- **If you use a [framework](/learn/creating-a-react-app#full-stack-frameworks), use its built-in data fetching mechanism.** Modern React frameworks have integrated data fetching mechanisms that are efficient and don't suffer from the above pitfalls.
737738
=======
738739
- **If you use a [framework](/learn/start-a-new-react-project#full-stack-frameworks), use its built-in data fetching mechanism.** Modern React frameworks have integrated data fetching mechanisms that are efficient and don't suffer from the above pitfalls.
739740
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
741+
=======
742+
- **If you use a [framework](/learn/start-a-new-react-project#full-stack-frameworks), use its built-in data fetching mechanism.** Modern React frameworks have integrated data fetching mechanisms that are efficient and don't suffer from the above pitfalls.
743+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
740744
- **Otherwise, consider using or building a client-side cache.** Popular open source solutions include [React Query](https://tanstack.com/query/latest), [useSWR](https://swr.vercel.app/), and [React Router 6.4+.](https://beta.reactrouter.com/en/main/start/overview) You can build your own solution too, in which case you would use Effects under the hood, but add logic for deduplicating requests, caching responses, and avoiding network waterfalls (by preloading data or hoisting data requirements to routes).
741745
742746
You can continue fetching data directly in Effects if neither of these approaches suit you.

src/content/learn/typescript.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ TypeScript is a popular way to add type definitions to JavaScript codebases. Out
2020

2121
## Installation {/*installation*/}
2222

23+
<<<<<<< HEAD
2324
<<<<<<< HEAD
2425
All [production-grade React frameworks](/learn/creating-a-react-app#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
2526
=======
2627
All [production-grade React frameworks](/learn/start-a-new-react-project#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
2728
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
29+
=======
30+
All [production-grade React frameworks](/learn/start-a-new-react-project#full-stack-frameworks) offer support for using TypeScript. Follow the framework specific guide for installation:
31+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
2832
2933
- [Next.js](https://nextjs.org/docs/app/building-your-application/configuring/typescript)
3034
- [Remix](https://remix.run/docs/en/1.19.2/guides/typescript)

src/content/learn/you-might-not-need-an-effect.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,15 @@ There are two common cases in which you don't need Effects:
2626
* **You don't need Effects to transform data for rendering.** For example, let's say you want to filter a list before displaying it. You might feel tempted to write an Effect that updates a state variable when the list changes. However, this is inefficient. When you update the state, React will first call your component functions to calculate what should be on the screen. Then React will ["commit"](/learn/render-and-commit) these changes to the DOM, updating the screen. Then React will run your Effects. If your Effect *also* immediately updates the state, this restarts the whole process from scratch! To avoid the unnecessary render passes, transform all the data at the top level of your components. That code will automatically re-run whenever your props or state change.
2727
* **You don't need Effects to handle user events.** For example, let's say you want to send an `/api/buy` POST request and show a notification when the user buys a product. In the Buy button click event handler, you know exactly what happened. By the time an Effect runs, you don't know *what* the user did (for example, which button was clicked). This is why you'll usually handle user events in the corresponding event handlers.
2828

29+
<<<<<<< HEAD
2930
<<<<<<< HEAD
3031
You *do* need Effects to [synchronize](/learn/synchronizing-with-effects#what-are-effects-and-how-are-they-different-from-events) with external systems. For example, you can write an Effect that keeps a jQuery widget synchronized with the React state. You can also fetch data with Effects: for example, you can synchronize the search results with the current search query. Keep in mind that modern [frameworks](/learn/creating-a-react-app#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components.
3132
=======
3233
You *do* need Effects to [synchronize](/learn/synchronizing-with-effects#what-are-effects-and-how-are-they-different-from-events) with external systems. For example, you can write an Effect that keeps a jQuery widget synchronized with the React state. You can also fetch data with Effects: for example, you can synchronize the search results with the current search query. Keep in mind that modern [frameworks](/learn/start-a-new-react-project#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components.
3334
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
35+
=======
36+
You *do* need Effects to [synchronize](/learn/synchronizing-with-effects#what-are-effects-and-how-are-they-different-from-events) with external systems. For example, you can write an Effect that keeps a jQuery widget synchronized with the React state. You can also fetch data with Effects: for example, you can synchronize the search results with the current search query. Keep in mind that modern [frameworks](/learn/start-a-new-react-project#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than writing Effects directly in your components.
37+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
3438
3539
To help you gain the right intuition, let's look at some common concrete examples!
3640

@@ -761,11 +765,15 @@ This ensures that when your Effect fetches data, all responses except the last r
761765
762766
Handling race conditions is not the only difficulty with implementing data fetching. You might also want to think about caching responses (so that the user can click Back and see the previous screen instantly), how to fetch data on the server (so that the initial server-rendered HTML contains the fetched content instead of a spinner), and how to avoid network waterfalls (so that a child can fetch data without waiting for every parent).
763767
768+
<<<<<<< HEAD
764769
<<<<<<< HEAD
765770
**These issues apply to any UI library, not just React. Solving them is not trivial, which is why modern [frameworks](/learn/creating-a-react-app#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.**
766771
=======
767772
**These issues apply to any UI library, not just React. Solving them is not trivial, which is why modern [frameworks](/learn/start-a-new-react-project#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.**
768773
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
774+
=======
775+
**These issues apply to any UI library, not just React. Solving them is not trivial, which is why modern [frameworks](/learn/start-a-new-react-project#full-stack-frameworks) provide more efficient built-in data fetching mechanisms than fetching data in Effects.**
776+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
769777
770778
If you don't use a framework (and don't want to build your own) but would like to make data fetching from Effects more ergonomic, consider extracting your fetching logic into a custom Hook like in this example:
771779

src/content/reference/react-dom/client/createRoot.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,15 @@ When your HTML is empty, the user sees a blank page until the app's JavaScript c
209209
<div id="root"></div>
210210
```
211211
212+
<<<<<<< HEAD
212213
<<<<<<< HEAD
213214
This can feel very slow! To solve this, you can generate the initial HTML from your components [on the server or during the build.](/reference/react-dom/server) Then your visitors can read text, see images, and click links before any of the JavaScript code loads. We recommend [using a framework](/learn/creating-a-react-app#full-stack-frameworks) that does this optimization out of the box. Depending on when it runs, this is called *server-side rendering (SSR)* or *static site generation (SSG).*
214215
=======
215216
This can feel very slow! To solve this, you can generate the initial HTML from your components [on the server or during the build.](/reference/react-dom/server) Then your visitors can read text, see images, and click links before any of the JavaScript code loads. We recommend [using a framework](/learn/start-a-new-react-project#full-stack-frameworks) that does this optimization out of the box. Depending on when it runs, this is called *server-side rendering (SSR)* or *static site generation (SSG).*
216217
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
218+
=======
219+
This can feel very slow! To solve this, you can generate the initial HTML from your components [on the server or during the build.](/reference/react-dom/server) Then your visitors can read text, see images, and click links before any of the JavaScript code loads. We recommend [using a framework](/learn/start-a-new-react-project#full-stack-frameworks) that does this optimization out of the box. Depending on when it runs, this is called *server-side rendering (SSR)* or *static site generation (SSG).*
220+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
217221
218222
</Note>
219223

src/content/reference/react-dom/client/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ title: Client React DOM APIs
44

55
<Intro>
66

7+
<<<<<<< HEAD
78
<<<<<<< HEAD
89
The `react-dom/client` APIs let you render React components on the client (in the browser). These APIs are typically used at the top level of your app to initialize your React tree. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
910
=======
1011
The `react-dom/client` APIs let you render React components on the client (in the browser). These APIs are typically used at the top level of your app to initialize your React tree. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
1112
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
13+
=======
14+
The `react-dom/client` APIs let you render React components on the client (in the browser). These APIs are typically used at the top level of your app to initialize your React tree. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
15+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
1216
1317
</Intro>
1418

src/content/reference/react-dom/server/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ title: Server React DOM APIs
44

55
<Intro>
66

7+
<<<<<<< HEAD
78
<<<<<<< HEAD
89
The `react-dom/server` APIs let you server-side render React components to HTML. These APIs are only used on the server at the top level of your app to generate the initial HTML. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
910
=======
1011
The `react-dom/server` APIs let you server-side render React components to HTML. These APIs are only used on the server at the top level of your app to generate the initial HTML. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
1112
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
13+
=======
14+
The `react-dom/server` APIs let you server-side render React components to HTML. These APIs are only used on the server at the top level of your app to generate the initial HTML. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
15+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
1216
1317
</Intro>
1418

src/content/reference/react-dom/static/index.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@ title: Static React DOM APIs
44

55
<Intro>
66

7+
<<<<<<< HEAD
78
<<<<<<< HEAD
89
The `react-dom/static` APIs let you generate static HTML for React components. They have limited functionality compared to the streaming APIs. A [framework](/learn/creating-a-react-app#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
910
=======
1011
The `react-dom/static` APIs let you generate static HTML for React components. They have limited functionality compared to the streaming APIs. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
1112
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
13+
=======
14+
The `react-dom/static` APIs let you generate static HTML for React components. They have limited functionality compared to the streaming APIs. A [framework](/learn/start-a-new-react-project#full-stack-frameworks) may call them for you. Most of your components don't need to import or use them.
15+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
1216
1317
</Intro>
1418

src/content/reference/react-dom/static/prerender.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to
7575
<<<<<<< HEAD
7676
<<<<<<< HEAD
7777
<<<<<<< HEAD
78+
<<<<<<< HEAD
7879
`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the a nonce value in the prerender itself.
7980
=======
8081
`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself.
@@ -97,6 +98,9 @@ On the client, call [`hydrateRoot`](/reference/react-dom/client/hydrateRoot) to
9798
=======
9899
`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself.
99100
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
101+
=======
102+
`nonce` is not an available option when prerendering. Nonces must be unique per request and if you use nonces to secure your application with [CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP) it would be inappropriate and insecure to include the nonce value in the prerender itself.
103+
>>>>>>> e07ac94bc2c1ffd817b13930977be93325e5bea9
100104
101105
102106
<Note>

0 commit comments

Comments
 (0)