Skip to content

Commit 1e32082

Browse files
authored
Merge pull request #172 from reactjs/sync-7b6c3ceb
Sync with react.dev @ 7b6c3ce
2 parents 1a248b1 + 9ac7507 commit 1e32082

12 files changed

Lines changed: 91 additions & 52 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@babel/preset-react": "^7.18.6",
5353
"@mdx-js/mdx": "^2.1.3",
5454
"@resvg/resvg-js": "^2.6.2",
55+
"@shuding/opentype.js": "1.4.0-beta.0",
5556
"@types/body-scroll-lock": "^2.6.1",
5657
"@types/classnames": "^2.2.10",
5758
"@types/debounce": "^1.2.1",

scripts/generateOgImages.mjs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import path from 'path';
1414
import satori from 'satori';
1515
import {Resvg} from '@resvg/resvg-js';
1616
import matter from 'gray-matter';
17+
import opentype from '@shuding/opentype.js';
1718

1819
const ROOT = process.cwd();
1920
const CONTENT_DIR = path.join(ROOT, 'src', 'content');
@@ -34,6 +35,33 @@ const medium = fs.readFileSync(
3435
path.join(ROOT, 'public', 'fonts', 'Optimistic_Display_W_Md.ttf')
3536
);
3637

38+
// Title area width: card width minus the horizontal padding (80px per side).
39+
const TITLE_MAX_WIDTH = 1200 - 80 * 2;
40+
const TITLE_MAX_FONT = 96;
41+
const TITLE_MIN_FONT = 56;
42+
// Small margin so borderline titles don't wrap and orphan a single trailing
43+
// character (e.g. the "p" in "renderToStaticMarkup", which is 1px too wide
44+
// to fit on one line at 96px).
45+
const TITLE_SAFETY = 8;
46+
47+
const boldFont = opentype.parse(
48+
bold.buffer.slice(bold.byteOffset, bold.byteOffset + bold.byteLength)
49+
);
50+
51+
// Multi-word titles wrap cleanly at spaces, so a length bucket is fine for
52+
// them. Single-word titles (most API names) can only break mid-word, which
53+
// leaves an orphaned letter on its own line, so instead shrink them just
54+
// enough to fit on a single line.
55+
function titleFontSize(title) {
56+
const trimmed = title.trim();
57+
if (/\s/.test(trimmed)) {
58+
return trimmed.length > 24 ? 72 : 96;
59+
}
60+
const widthPerPx = boldFont.getAdvanceWidth(trimmed, 1);
61+
const fit = Math.floor((TITLE_MAX_WIDTH - TITLE_SAFETY) / widthPerPx);
62+
return Math.max(TITLE_MIN_FONT, Math.min(TITLE_MAX_FONT, fit));
63+
}
64+
3765
function el(type, style, children) {
3866
return {type, props: {style, children}};
3967
}
@@ -103,7 +131,7 @@ function card(title, pagePath) {
103131
flexGrow: 1,
104132
display: 'flex',
105133
alignItems: 'center',
106-
fontSize: title.length > 24 ? 72 : 96,
134+
fontSize: titleFontSize(title),
107135
fontFamily: 'Optimistic Display Bold',
108136
color: '#f6f7f9',
109137
lineHeight: 1.1,

src/content/learn/editor-setup.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ Baadhi ya vihariri huja na maumbile haya yakiwa yamejengwa ndani, lakini vingine
3131

3232
### Linting {/*linting*/}
3333

34+
<<<<<<< HEAD
3435
Code linters hupata matatizo katika kodi yako unapoandika, zikikusaidia kuyarekebisha mapema. [ESLint](https://eslint.org/) ni linter maarufu ya chanzo wazi (open source) kwa ajili ya JavaScript.
36+
=======
37+
Code linters find problems in your code as you write, helping you fix them early. [ESLint](https://eslint.org/) is a popular, open source linter for JavaScript.
38+
>>>>>>> 7b6c3ceb9dd97249e9dce4a8a94e61aed6424698
3539
3640
* [Sakinisha ESLint kwa mpangilio uliopendekezwa kwa React](https://www.npmjs.com/package/eslint-config-react-app) (hakikisha una [Node imesakinishwa!](https://nodejs.org/en/download/current/))
3741
* [Unganisha ESLint katika VSCode na kiendelezi rasmi](https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint)

src/content/learn/thinking-in-react.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ Anza kwa kuchora visanduku kuzunguka kila kijenzi na kijenzi kidogo kwenye kiigi
3737

3838
Kulingana na msingi wako, unaweza kufikiria kugawanya muundo katika vijenzi kwa njia tofauti:
3939

40+
<<<<<<< HEAD
4041
* **Programming**--tumia mbinu zile zile za kuamua ikiwa unapaswa kuunda kitendaji kipya au object. Mbinu moja kama hiyo ni [kanuni ya uwajibikaji mmoja (single responsibility principle)](https://en.wikipedia.org/wiki/Single_responsibility_principle), yaani, kijenzi kinapaswa kufanya jambo moja tu. Ikiwa kitaishia kukua, inapaswa kigawanywe kiwe vijenzi vidogo.
4142
* **CSS**--fikiria ni nini ungetengeneza viteule vya darasa. (Hatahivyo, vijenzi ni vidogo kwa kiasi fulani.)
4243
* **Design**--fikiria jinsi unavyoweza kupanga safu za muundo.
44+
=======
45+
* **Programming**--use the same techniques for deciding if you should create a new function or object. One such technique is the [separation of concerns](https://en.wikipedia.org/wiki/Separation_of_concerns), that is, a component should ideally only be concerned with one thing. If it ends up growing, it should be decomposed into smaller subcomponents.
46+
* **CSS**--consider what you would make class selectors for. (However, components are a bit less granular.)
47+
* **Design**--consider how you would organize the design's layers.
48+
>>>>>>> 7b6c3ceb9dd97249e9dce4a8a94e61aed6424698
4349
4450
Ikiwa JSON yako imeundwa vizuri, mara nyingi utapata kwamba inaelekeza kwa muundo wa vijenzi vya UI yako. Hiyo ni kwa sababu UI na miundo ya data mara nyingi huwa na usanifu sawa wa habari--yaani, umbo sawa. Tenganisha UI yako katika vijenzi, ambapo kila kijenzi kinalingana na kipande kimoja cha muundo yako wa data.
4551

@@ -226,10 +232,19 @@ Kilichobaki labda ni hali.
226232

227233
Wacha tupitie moja baada ya nyingine tena:
228234

235+
<<<<<<< HEAD
229236
1. Orodha asili ya bidhaa **imepitishwa kama vifaa, kwa hivyo haijabainishwa.**
230237
2. Maandishi ya utafutaji yanaonekana kuwa ya hali kwani yanabadilika kwa wakati na hayawezi kukokotwa kutoka kwa chochote.
231238
3. Thamani ya kisanduku cha kuteua inaonekana kuwa hali kwani inabadilika kwa wakati na haiwezi kukokotwa kutoka kwa chochote.
232239
4. Orodha iliyochujwa ya bidhaa **haijabainishwa kwa sababu inaweza kukokotwa** kwa kuchukua orodha asili ya bidhaa na kuichuja kulingana na maandishi ya utafutaji na thamani ya kisanduku cha kuteua.
240+
=======
241+
1. The original list of products is **passed in as props, so it's not state.**
242+
2. The search text seems to be state since it changes over time and can't be computed from anything.
243+
3. The value of the checkbox seems to be state since it changes over time and can't be computed from anything.
244+
4. The filtered list of products **isn't state because it can be computed** by taking the original list of products and filtering it according to the search text and value of the checkbox.
245+
246+
This means only the search text and the value of the checkbox are state! Nicely done!
247+
>>>>>>> 7b6c3ceb9dd97249e9dce4a8a94e61aed6424698
233248
234249
Hii ina maana kwamba ni maandishi ya utafutaji pekee na thamani ya kisanduku cha kuteua ndizo zilizotajwa! Imefanywa vizuri!
235250
<DeepDive>
@@ -262,13 +277,23 @@ In the previous step, you found two pieces of state in this application: the sea
262277

263278
Katika hatua ya awali, ulipata vipande viwili vya hali katika programu hii: maandishi ya ingizo ya utafutaji, na thamani ya kisanduku cha kuteua. Katika mfano huu, daima huonekana pamoja, kwa hiyo ni mantiki kuviweka katika sehemu moja.
264279

280+
<<<<<<< HEAD
265281
Sasa wacha tupitie mkakati wetu kwao:
266282

267283
1. **Tambua vijenzi vinavyotumia hali:**
268284
* `ProductTable` inahitaji kuchuja orodha ya bidhaa kulingana na hali hiyo (maandishi ya utafutaji na thamani ya kisanduku cha kuteua).
269285
* `SearchBar` inahitaji kuonyesha hali hiyo (maandishi ya utafutaji na thamani ya kisanduku cha kuteua).
270286
1. **Tafuta mzazi wao wa kawaida:** Kijenzi mzazi cha kwanza ambacho vijenzi vyote viwili hushiriki ni `FilterableProductTable`.
271287
2. **Amua mahali pa kuishi**: Tutaweka maandishi ya kichujio na thamani za hali zilizochaguliwa katika `FilterableProductTable`.
288+
=======
289+
1. **Identify components that use state:**
290+
* `ProductTable` needs to filter the product list based on that state (search text and checkbox value).
291+
* `SearchBar` needs to display that state (search text and checkbox value).
292+
2. **Find their common parent:** The first parent component both components share is `FilterableProductTable`.
293+
3. **Decide where the state lives**: We'll keep the filter text and checked state values in `FilterableProductTable`.
294+
295+
So the state values will live in `FilterableProductTable`.
296+
>>>>>>> 7b6c3ceb9dd97249e9dce4a8a94e61aed6424698
272297
273298
Kwa hivyo state thamani zitaishi katika `FilterableProductTable`.
274299

@@ -456,7 +481,16 @@ function SearchBar({ filterText, inStockOnly }) {
456481
457482
Hata hivyo, bado hujaongeza msimbo wowote ili kujibu vitendo vya mtumiaji kama vile kuandika. Hii itakuwa hatua yako ya mwisho.
458483
484+
<<<<<<< HEAD
459485
## Hatua ya 5: Ongeza mtiririko wa data kinyume {/*step-5-add-inverse-data-flow*/}
486+
=======
487+
488+
## Step 5: Add inverse data flow {/*step-5-add-inverse-data-flow*/}
489+
490+
Currently your app renders correctly with props and state flowing down the hierarchy. But to change the state according to user input, you will need to support data flowing the other way: the form components deep in the hierarchy need to update the state in `FilterableProductTable`.
491+
492+
React makes this data flow explicit, but it requires a little more typing than two-way data binding. If you try to type or check the box in the example above, you'll see that React ignores your input. This is intentional. By writing `<input value={filterText} />`, you've set the `value` prop of the `input` to always be equal to the `filterText` state passed in from `FilterableProductTable`. Since `filterText` state is never set, the input never changes.
493+
>>>>>>> 7b6c3ceb9dd97249e9dce4a8a94e61aed6424698
460494
461495
You want to make it so whenever the user changes the form inputs, the state updates to reflect those changes. The state is owned by `FilterableProductTable`, so only it can call `setFilterText` and `setInStockOnly`. To let `SearchBar` update the `FilterableProductTable`'s state, you need to pass these functions down to `SearchBar`:
462496

src/content/learn/tutorial-tic-tac-toe.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -906,11 +906,6 @@ React DevTools hukuruhusu kuangalia *props* na *state* za vipengele vyako vya Re
906906
Ili kuchunguza kipengele fulani kwenye skrini, tumia kitufe kilicho kwenye kona ya juu kushoto ya React DevTools:
907907
908908
![Kuchagua vipengele kwenye ukurasa na React DevTools](../images/tutorial/devtools-select.gif)
909-
After you install it, a new *Components* tab will appear in your browser Developer Tools for sites using React. If you're following along in CodeSandbox, you'd need to first open your sandbox preview in a new tab:
910-
911-
![opening in new tab](../images/tutorial/sandbox-new-tab.png)
912-
913-
Then, on the preview page, open your browser's DevTools and find the *Components* tab:
914909
915910
![components tab](../images/tutorial/components-tab.png)
916911

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -284,17 +284,7 @@ Streaming does not need to wait for React itself to load in the browser, or for
284284
285285
<Note>
286286
287-
**Only Suspense-enabled data sources will activate the Suspense component.** They include:
288-
289-
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
290-
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
291-
- Reading the value of a Promise with [`use`](/reference/react/use)
292-
293-
Suspense **does not** detect when data is fetched inside an Effect or event handler.
294-
295-
The exact way you would load data in the `Posts` component above depends on your framework. If you use a Suspense-enabled framework, you'll find the details in its data fetching documentation.
296-
297-
Suspense-enabled data fetching without the use of an opinionated framework is not yet supported. The requirements for implementing a Suspense-enabled data source are unstable and undocumented. An official API for integrating data sources with Suspense will be released in a future version of React.
287+
Only data read from a source that [activates a Suspense boundary](/reference/react/Suspense#what-activates-a-suspense-boundary), such as a Promise read with [`use`](/reference/react/use), will suspend during rendering. Suspense does not detect data fetched inside an Effect or event handler.
298288
299289
</Note>
300290

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,7 @@ Streaming does not need to wait for React itself to load in the browser, or for
283283
284284
<Note>
285285
286-
**Only Suspense-enabled data sources will activate the Suspense component.** They include:
287-
288-
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/getting-started/react-essentials)
289-
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
290-
- Reading the value of a Promise with [`use`](/reference/react/use)
291-
292-
Suspense **does not** detect when data is fetched inside an Effect or event handler.
293-
294-
The exact way you would load data in the `Posts` component above depends on your framework. If you use a Suspense-enabled framework, you'll find the details in its data fetching documentation.
295-
296-
Suspense-enabled data fetching without the use of an opinionated framework is not yet supported. The requirements for implementing a Suspense-enabled data source are unstable and undocumented. An official API for integrating data sources with Suspense will be released in a future version of React.
286+
Only data read from a source that [activates a Suspense boundary](/reference/react/Suspense#what-activates-a-suspense-boundary), such as a Promise read with [`use`](/reference/react/use), will suspend during rendering. Suspense does not detect data fetched inside an Effect or event handler.
297287
298288
</Note>
299289

src/content/reference/react/Activity.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -755,17 +755,7 @@ Pre-rendering components with hidden Activity boundaries is a powerful way to re
755755

756756
<Note>
757757

758-
**Only Suspense-enabled data sources will be fetched during pre-rendering.** They include:
759-
760-
- Data fetching with Suspense-enabled frameworks like [Relay](https://relay.dev/docs/guided-tour/rendering/loading-states/) and [Next.js](https://nextjs.org/docs/app/building-your-application/routing/loading-ui-and-streaming#streaming-with-suspense)
761-
- Lazy-loading component code with [`lazy`](/reference/react/lazy)
762-
- Reading the value of a cached Promise with [`use`](/reference/react/use)
763-
764-
Activity **does not** detect data that is fetched inside an Effect.
765-
766-
The exact way you would load data in the `Posts` component above depends on your framework. If you use a Suspense-enabled framework, you'll find the details in its data fetching documentation.
767-
768-
Suspense-enabled data fetching without the use of an opinionated framework is not yet supported. The requirements for implementing a Suspense-enabled data source are unstable and undocumented. An official API for integrating data sources with Suspense will be released in a future version of React.
758+
Only data read from a source that [activates a Suspense boundary](/reference/react/Suspense#what-activates-a-suspense-boundary), such as a Promise read with [`use`](/reference/react/use), is fetched during pre-rendering. Activity does not detect data fetched inside an Effect.
769759

770760
</Note>
771761

src/content/reference/react/Fragment.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,7 @@ Wrap elements in `<Fragment>` to group them together in situations where you nee
3838

3939
* React does not [reset state](/learn/preserving-and-resetting-state) when you go from rendering `<><Child /></>` to `[<Child />]` or back, or when you go from rendering `<><Child /></>` to `<Child />` and back. This only works a single level deep: for example, going from `<><><Child /></></>` to `<Child />` resets the state. See the precise semantics [here.](https://gist.github.com/clemmy/b3ef00f9507909429d8aa0d3ee4f986b)
4040

41-
**Layout methods:**
42-
- `compareDocumentPosition(otherNode)`: Compares the document position of the Fragment with another node.
43-
- If the Fragment has children, the native `compareDocumentPosition` value is returned.
44-
- Empty Fragments will attempt to compare positioning within the React tree and include `Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC`.
45-
- Elements that have a different relationship in the React tree and DOM tree due to portaling or other insertions are `Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC`.
46-
- `getClientRects()`: Returns a flat array of `DOMRect` objects representing the bounding rectangles of all children.
47-
- `getRootNode()`: Returns the root node containing the Fragment's parent DOM node.
41+
* <CanaryBadge /> If you want to pass `ref` to a Fragment, you can't use the `<>...</>` syntax. You have to explicitly import `Fragment` from `'react'` and render `<Fragment ref={yourRef}>...</Fragment>`.
4842

4943
---
5044

@@ -765,10 +759,12 @@ function VisibleGroup({ onVisibilityChange, children }) {
765759
onVisibilityChange(visibleElements.size > 0);
766760
}
767761
);
768-
769-
fragmentRef.current.observeUsing(observer);
770-
return () => fragmentRef.current.unobserveUsing(observer);
771-
}, [threshold, onVisibilityChange]);
762+
const fragmentInstance = fragmentRef.current;
763+
fragmentInstance.observeUsing(observer);
764+
return () => {
765+
fragmentInstance.unobserveUsing(observer);
766+
};
767+
}, [onVisibilityChange]);
772768

773769
return (
774770
<Fragment ref={fragmentRef}>

src/content/reference/react/Suspense.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,17 @@ import { fetchData } from './data.js';
286286
export default function EffectAlbums({ artistId }) {
287287
const [albums, setAlbums] = useState([]);
288288

289-
Suspense-enabled data fetching without the use of an opinionated framework is not yet supported. The requirements for implementing a Suspense-enabled data source are unstable and undocumented. An official API for integrating data sources with Suspense will be released in a future version of React.
289+
useEffect(() => {
290+
let active = true;
291+
fetchData(`/${artistId}/albums`).then(result => {
292+
if (active) {
293+
setAlbums(result);
294+
}
295+
});
296+
return () => {
297+
active = false;
298+
};
299+
}, [artistId]);
290300

291301
// Suspense can't see this fetch, so its fallback never
292302
// shows. The list stays empty until the data arrives.

0 commit comments

Comments
 (0)