Skip to content

Commit 04d3c14

Browse files
authored
Merge pull request #469 from reactjs/sync-65d297e9
Sync with react.dev @ 65d297e
2 parents bf6197b + a34ac34 commit 04d3c14

20 files changed

+192
-21
lines changed
75.6 KB
Binary file not shown.
64.9 KB
Binary file not shown.
Binary file not shown.

src/components/Layout/HomeContent.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,8 @@ function ExampleLayout({
859859
</div>
860860
<div
861861
ref={contentRef}
862-
className="relative mt-0 lg:-my-20 w-full p-2.5 xs:p-5 lg:p-10 flex grow justify-center">
862+
className="relative mt-0 lg:-my-20 w-full p-2.5 xs:p-5 lg:p-10 flex grow justify-center"
863+
dir="ltr">
863864
{right}
864865
<div
865866
className={cn(

src/components/MDX/Sandpack/template.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const template = {
22
'/src/index.js': {
33
hidden: true,
4-
code: `import React, { StrictMode } from "react";
4+
code: `import { StrictMode } from "react";
55
import { createRoot } from "react-dom/client";
66
import "./styles.css";
77

src/components/PageHeading.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ function PageHeading({
2727
tags = [],
2828
breadcrumbs,
2929
}: PageHeadingProps) {
30-
console.log('version', version);
3130
return (
3231
<div className="px-5 sm:px-12 pt-3.5">
3332
<div className="max-w-4xl ms-0 2xl:mx-auto">

src/components/Seo.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,14 @@ export const Seo = withRouter(
124124
)}
125125
<link
126126
rel="preload"
127-
href="/fonts/Source-Code-Pro-Regular.woff2"
127+
href="https://react.dev/fonts/Source-Code-Pro-Regular.woff2"
128+
as="font"
129+
type="font/woff2"
130+
crossOrigin="anonymous"
131+
/>
132+
<link
133+
rel="preload"
134+
href="https://react.dev/fonts/Source-Code-Pro-Bold.woff2"
128135
as="font"
129136
type="font/woff2"
130137
crossOrigin="anonymous"

src/content/community/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Mỗi cộng đồng bao gồm hàng nghìn người dùng React.
3131

3232
## Tin tức {/*news*/}
3333

34-
Để biết thêm tin tức mới nhất về React, [theo dõi **@reactjs** trên Twitter](https://twitter.com/reactjs) [blog chính thức của React](/blog/) trên trang này.
34+
Để biết thêm tin tức mới nhất về React, [theo dõi **@reactjs** trên Twitter](https://twitter.com/reactjs), [**@react.dev** trên Bluesky](https://bsky.app/profile/react.dev) [blog chính thức của React](/blog/) trên website này.

src/content/community/meetups.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Bạn đã có React.js meetup tại quốc gia của bạn chưa? Thêm nó và
3838

3939
## Canada {/*canada*/}
4040
* [Halifax, NS](https://www.meetup.com/Halifax-ReactJS-Meetup/)
41-
* [Montreal, QC - React Native](https://www.meetup.com/fr-FR/React-Native-MTL/)
41+
* [Montreal, QC](https://guild.host/react-montreal/)
4242
* [Vancouver, BC](https://www.meetup.com/ReactJS-Vancouver-Meetup/)
4343
* [Ottawa, ON](https://www.meetup.com/Ottawa-ReactJS-Meetup/)
4444
* [Saskatoon, SK](https://www.meetup.com/saskatoon-react-meetup/)

src/content/learn/build-a-react-app-from-scratch.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Similarly, if you rely on the apps using your framework to split the code, you m
116116
Splitting code by route, when integrated with bundling and data fetching, can reduce the initial load time of your app and the time it takes for the largest visible content of the app to render ([Largest Contentful Paint](https://web.dev/articles/lcp)).
117117

118118
For code-splitting instructions, see your build tool docs:
119-
- [Vite build optimizations](https://v3.vitejs.dev/guide/features.html#build-optimizations)
119+
- [Vite build optimizations](https://vite.dev/guide/features.html#build-optimizations)
120120
- [Parcel code splitting](https://parceljs.org/features/code-splitting/)
121121
- [Rsbuild code splitting](https://rsbuild.dev/guide/optimization/code-splitting)
122122

src/content/learn/preserving-and-resetting-state.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ export default function ContactList() {
20112011
<label>
20122012
<input
20132013
type="checkbox"
2014-
value={reverse}
2014+
checked={reverse}
20152015
onChange={e => {
20162016
setReverse(e.target.checked)
20172017
}}
@@ -2110,7 +2110,7 @@ export default function ContactList() {
21102110
<label>
21112111
<input
21122112
type="checkbox"
2113-
value={reverse}
2113+
checked={reverse}
21142114
onChange={e => {
21152115
setReverse(e.target.checked)
21162116
}}

src/content/learn/removing-effect-dependencies.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ export default function Timer() {
12411241
12421242
</Sandpack>
12431243
1244-
Instead of reading `count` inside the Effect, you pass a `c => c + 1` instruction ("increment this number!") to React. React will apply it on the next render. And since you don't need to read the value of `count` inside your Effect anymore, so you can keep your Effect's dependencies empty (`[]`). This prevents your Effect from re-creating the interval on every tick.
1244+
Instead of reading `count` inside the Effect, you pass a `c => c + 1` instruction ("increment this number!") to React. React will apply it on the next render. And since you don't need to read the value of `count` inside your Effect anymore, you can keep your Effect's dependencies empty (`[]`). This prevents your Effect from re-creating the interval on every tick.
12451245
12461246
</Solution>
12471247

src/content/learn/reusing-logic-with-custom-hooks.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ export default function ChatRoom({ roomId }) {
820820
// ...
821821
```
822822
823-
and pass it as an input to another Hook:
823+
and passing it as an input to another Hook:
824824
825825
```js {6}
826826
export default function ChatRoom({ roomId }) {
@@ -2081,7 +2081,6 @@ Write `useInterval` in the `useInterval.js` file and import it into the `useCoun
20812081
<Sandpack>
20822082
20832083
```js
2084-
import { useState } from 'react';
20852084
import { useCounter } from './useCounter.js';
20862085

20872086
export default function Counter() {

src/content/learn/separating-events-from-effects.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ function ChatRoom({ roomId, theme }) {
439439
// ...
440440
```
441441
442-
This solves the problem. Note that you had to *remove* `onConnected` from the list of your Effect's dependencies. **Effect Events are not reactive and must be omitted from dependencies.**
442+
This solves the problem. Note that you had to *remove* `theme` from the list of your Effect's dependencies, because it's no longer used in the Effect. You also don't need to *add* `onConnected` to it, because **Effect Events are not reactive and must be omitted from dependencies.**
443443
444444
Verify that the new behavior works as you would expect:
445445

src/content/reference/react-dom/preinit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The `preinit` function provides the browser with a hint that it should start dow
4848
* `options`: an object. It contains the following properties:
4949
* `as`: a required string. The type of resource. Its possible values are `script` and `style`.
5050
* `precedence`: a string. Required with stylesheets. Says where to insert the stylesheet relative to others. Stylesheets with higher precedence can override those with lower precedence. The possible values are `reset`, `low`, `medium`, `high`.
51-
* `crossOrigin`: a string. The [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) to use. Its possible values are `anonymous` and `use-credentials`. It is required when `as` is set to `"fetch"`.
51+
* `crossOrigin`: a string. The [CORS policy](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin) to use. Its possible values are `anonymous` and `use-credentials`.
5252
* `integrity`: a string. A cryptographic hash of the resource, to [verify its authenticity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
5353
* `nonce`: a string. A cryptographic [nonce to allow the resource](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/nonce) when using a strict Content Security Policy.
5454
* `fetchPriority`: a string. Suggests a relative priority for fetching the resource. The possible values are `auto` (the default), `high`, and `low`.

src/content/reference/react/useTransition.md

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function CheckoutForm() {
163163

164164
The function passed to `startTransition` is called the "Action". You can update state and (optionally) perform side effects within an Action, and the work will be done in the background without blocking user interactions on the page. A Transition can include multiple Actions, and while a Transition is in progress, your UI stays responsive. For example, if the user clicks a tab but then changes their mind and clicks another tab, the second click will be immediately handled without waiting for the first update to finish.
165165

166-
To give the user feedback about in-progress Transitions, to `isPending` state switches to `true` at the first call to `startTransition`, and stays `true` until all Actions complete and the final state is shown to the user. Transitions ensure side effects in Actions to complete in order to [prevent unwanted loading indicators](#preventing-unwanted-loading-indicators), and you can provide immediate feedback while the Transition is in progress with `useOptimistic`.
166+
To give the user feedback about in-progress Transitions, the `isPending` state switches to `true` at the first call to `startTransition`, and stays `true` until all Actions complete and the final state is shown to the user. Transitions ensure side effects in Actions to complete in order to [prevent unwanted loading indicators](#preventing-unwanted-loading-indicators), and you can provide immediate feedback while the Transition is in progress with `useOptimistic`.
167167

168168
<Recipes titleText="The difference between Actions and regular event handling">
169169

@@ -1948,3 +1948,162 @@ When clicking multiple times, it's possible for previous requests to finish afte
19481948
This is expected, because Actions within a Transition do not guarantee execution order. For common use cases, React provides higher-level abstractions like [`useActionState`](/reference/react/useActionState) and [`<form>` actions](/reference/react-dom/components/form) that handle ordering for you. For advanced use cases, you'll need to implement your own queuing and abort logic to handle this.
19491949
19501950
1951+
Example of `useActionState` handling execution order:
1952+
1953+
<Sandpack>
1954+
1955+
```json package.json hidden
1956+
{
1957+
"dependencies": {
1958+
"react": "beta",
1959+
"react-dom": "beta"
1960+
},
1961+
"scripts": {
1962+
"start": "react-scripts start",
1963+
"build": "react-scripts build",
1964+
"test": "react-scripts test --env=jsdom",
1965+
"eject": "react-scripts eject"
1966+
}
1967+
}
1968+
```
1969+
1970+
```js src/App.js
1971+
import { useState, useActionState } from "react";
1972+
import { updateQuantity } from "./api";
1973+
import Item from "./Item";
1974+
import Total from "./Total";
1975+
1976+
export default function App({}) {
1977+
// Store the actual quantity in separate state to show the mismatch.
1978+
const [clientQuantity, setClientQuantity] = useState(1);
1979+
const [quantity, updateQuantityAction, isPending] = useActionState(
1980+
async (prevState, payload) => {
1981+
setClientQuantity(payload);
1982+
const savedQuantity = await updateQuantity(payload);
1983+
return savedQuantity; // Return the new quantity to update the state
1984+
},
1985+
1 // Initial quantity
1986+
);
1987+
1988+
return (
1989+
<div>
1990+
<h1>Checkout</h1>
1991+
<Item action={updateQuantityAction}/>
1992+
<hr />
1993+
<Total clientQuantity={clientQuantity} savedQuantity={quantity} isPending={isPending} />
1994+
</div>
1995+
);
1996+
}
1997+
1998+
```
1999+
2000+
```js src/Item.js
2001+
import {startTransition} from 'react';
2002+
2003+
export default function Item({action}) {
2004+
function handleChange(e) {
2005+
// Update the quantity in an Action.
2006+
startTransition(() => {
2007+
action(e.target.value);
2008+
});
2009+
}
2010+
return (
2011+
<div className="item">
2012+
<span>Eras Tour Tickets</span>
2013+
<label htmlFor="name">Quantity: </label>
2014+
<input
2015+
type="number"
2016+
onChange={handleChange}
2017+
defaultValue={1}
2018+
min={1}
2019+
/>
2020+
</div>
2021+
)
2022+
}
2023+
```
2024+
2025+
```js src/Total.js
2026+
const intl = new Intl.NumberFormat("en-US", {
2027+
style: "currency",
2028+
currency: "USD"
2029+
});
2030+
2031+
export default function Total({ clientQuantity, savedQuantity, isPending }) {
2032+
return (
2033+
<div className="total">
2034+
<span>Total:</span>
2035+
<div>
2036+
<div>
2037+
{isPending
2038+
? "🌀 Updating..."
2039+
: `${intl.format(savedQuantity * 9999)}`}
2040+
</div>
2041+
<div className="error">
2042+
{!isPending &&
2043+
clientQuantity !== savedQuantity &&
2044+
`Wrong total, expected: ${intl.format(clientQuantity * 9999)}`}
2045+
</div>
2046+
</div>
2047+
</div>
2048+
);
2049+
}
2050+
```
2051+
2052+
```js src/api.js
2053+
let firstRequest = true;
2054+
export async function updateQuantity(newName) {
2055+
return new Promise((resolve, reject) => {
2056+
if (firstRequest === true) {
2057+
firstRequest = false;
2058+
setTimeout(() => {
2059+
firstRequest = true;
2060+
resolve(newName);
2061+
// Simulate every other request being slower
2062+
}, 1000);
2063+
} else {
2064+
setTimeout(() => {
2065+
resolve(newName);
2066+
}, 50);
2067+
}
2068+
});
2069+
}
2070+
```
2071+
2072+
```css
2073+
.item {
2074+
display: flex;
2075+
align-items: center;
2076+
justify-content: start;
2077+
}
2078+
2079+
.item label {
2080+
flex: 1;
2081+
text-align: right;
2082+
}
2083+
2084+
.item input {
2085+
margin-left: 4px;
2086+
width: 60px;
2087+
padding: 4px;
2088+
}
2089+
2090+
.total {
2091+
height: 50px;
2092+
line-height: 25px;
2093+
display: flex;
2094+
align-content: center;
2095+
justify-content: space-between;
2096+
}
2097+
2098+
.total div {
2099+
display: flex;
2100+
flex-direction: column;
2101+
align-items: flex-end;
2102+
}
2103+
2104+
.error {
2105+
color: red;
2106+
}
2107+
```
2108+
2109+
</Sandpack>

src/content/reference/rsc/server-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ To support Server Functions as a bundler or framework, we recommend pinning to a
2828

2929
</Note>
3030

31-
When a Server Functions is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result.
31+
When a Server Function is defined with the [`"use server"`](/reference/rsc/use-server) directive, your framework will automatically create a reference to the server function, and pass that reference to the Client Component. When that function is called on the client, React will send a request to the server to execute the function, and return the result.
3232

3333
Server Functions can be created in Server Components and passed as props to Client Components, or they can be imported and used in Client Components.
3434

src/content/warnings/react-dom-test-utils.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: react-dom/test-utils Deprecation Warnings
33
---
44

5-
TODO: update for 19?
6-
75
## ReactDOMTestUtils.act() warning {/*reactdomtestutilsact-warning*/}
86

97
`act` from `react-dom/test-utils` has been deprecated in favor of `act` from `react`.

src/content/warnings/react-test-renderer.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
title: react-test-renderer Deprecation Warnings
33
---
44

5-
TODO: Update this for 19?
6-
75
## ReactTestRenderer.create() warning {/*reacttestrenderercreate-warning*/}
86

97
react-test-renderer is deprecated. A warning will fire whenever calling ReactTestRenderer.create() or ReactShallowRender.render(). The react-test-renderer package will remain available on NPM but will not be maintained and may break with new React features or changes to React's internals.

src/styles/index.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,17 @@
1212
font-style: normal;
1313
font-weight: 400;
1414
font-display: swap;
15-
src: url('/fonts/Source-Code-Pro-Regular.woff2') format('woff2');
15+
src: url('https://react.dev/fonts/Source-Code-Pro-Regular.woff2')
16+
format('woff2');
17+
}
18+
19+
@font-face {
20+
font-family: 'Source Code Pro';
21+
font-style: normal;
22+
font-weight: 700;
23+
font-display: swap;
24+
src: url('https://react.dev/fonts/Source-Code-Pro-Bold.woff2')
25+
format('woff2');
1626
}
1727

1828
/* Latin */

0 commit comments

Comments
 (0)