Skip to content

Commit 412b733

Browse files
authored
Blog post nits (#6779)
* Typos in React 19 * Headings
1 parent 191852a commit 412b733

File tree

2 files changed

+48
-54
lines changed

2 files changed

+48
-54
lines changed

src/content/blog/2024/04/25/react-19-upgrade-guide.md

+16-16
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ For a list of changes in 18.3 see the [Release Notes](https://github.com/faceboo
3636
In this post, we will guide you through the steps for upgrading libraries to React 19 beta:
3737

3838
- [Installing](#installing)
39-
- [Breaking Changes](#breaking-changes)
40-
- [New Deprecations](#new-deprecations)
41-
- [Notable Changes](#notable-changes)
42-
- [TypeScript Changes](#typescript-changes)
39+
- [Breaking changes](#breaking-changes)
40+
- [New deprecations](#new-deprecations)
41+
- [Notable changes](#notable-changes)
42+
- [TypeScript changes](#typescript-changes)
4343
- [Changelog](#changelog)
4444

4545
If you'd like to help us test React 19, follow the steps in this upgrade guide and [report any issues](https://github.com/facebook/react/issues/new?assignees=&labels=React+19&projects=&template=19.md&title=%5BReact+19%5D) you encounter. For a list of new features added to React 19 beta, see the [React 19 release post](/blog/2024/04/25/react-19).
@@ -92,10 +92,10 @@ If you're using TypeScript, you also need to update the types. Once React 19 is
9292
}
9393
```
9494

95-
We're also including a codemod for the most common replacements. See [Removed TypeScript Types](#removed-deprecated-typescript-types) below.
95+
We're also including a codemod for the most common replacements. See [TypeScript changes](#typescript-changes) below.
9696

9797

98-
## Breaking Changes {/*breaking-changes*/}
98+
## Breaking changes {/*breaking-changes*/}
9999

100100
### Errors in render are not re-thrown {/*errors-in-render-are-not-re-thrown*/}
101101

@@ -163,7 +163,7 @@ Legacy Context was only available in class components using the APIs `contextTyp
163163

164164
If you're still using Legacy Context in class components, you'll need to migrate to the new `contextType` API:
165165

166-
```js
166+
```js {5-11,19-21}
167167
// Before
168168
import PropTypes from 'prop-types';
169169

@@ -192,7 +192,7 @@ class Child extends React.Component {
192192
}
193193
```
194194

195-
```js
195+
```js {2,7,9,15}
196196
// After
197197
const FooContext = React.createContext();
198198

@@ -222,7 +222,7 @@ Class components supported string refs before being replaced by ref callbacks du
222222

223223
If you're still using string refs in class components, you'll need to migrate to ref callbacks:
224224

225-
```js
225+
```js {4,8}
226226
// Before
227227
class MyComponent extends React.Component {
228228
componentDidMount() {
@@ -235,7 +235,7 @@ class MyComponent extends React.Component {
235235
}
236236
```
237237

238-
```js
238+
```js {4,8}
239239
// After
240240
class MyComponent extends React.Component {
241241
componentDidMount() {
@@ -414,7 +414,7 @@ function AutoselectingInput() {
414414
}
415415
```
416416

417-
## New Deprecations {/*new-deprecations*/}
417+
## New deprecations {/*new-deprecations*/}
418418

419419
### Deprecated: `element.ref` {/*deprecated-element-ref*/}
420420

@@ -440,7 +440,7 @@ The test renderer was created before there were more viable testing strategies a
440440

441441
In React 19, `react-test-renderer` logs a deprecation warning, and has switched to concurrent rendering. We recommend migrating your tests to [@testing-library/react](https://testing-library.com/docs/react-testing-library/intro/) or [@testing-library/react-native](https://callstack.github.io/react-native-testing-library/docs/getting-started) for a modern and well supported testing experience.
442442

443-
## Notable Changes {/*notable-changes*/}
443+
## Notable changes {/*notable-changes*/}
444444

445445
### StrictMode changes {/*strict-mode-improvements*/}
446446

@@ -476,7 +476,7 @@ To reflect the impact of using internals, we have renamed the `SECRET_INTERNALS`
476476

477477
In the future we will more aggressively block accessing internals from React to discourage usage and ensure users are not blocked from upgrading.
478478

479-
## TypeScript Changes {/*typescript-changes*/}
479+
## TypeScript changes {/*typescript-changes*/}
480480

481481
### Removed deprecated TypeScript types {/*removed-deprecated-typescript-types*/}
482482

@@ -574,7 +574,7 @@ type Example = ReactElement["props"];
574574

575575
You should only need it if you have a lot of legacy code relying on unsound access of element props. Element introspection only exists as an escape hatch, and you should make it explicit that your props access is unsound via an explicit `any`.
576576

577-
### The JSX Namespace in TypeScript {/*the-jsx-namespace-in-typescript*/}
577+
### The JSX namespace in TypeScript {/*the-jsx-namespace-in-typescript*/}
578578
This change is included in the `react-19` codemod preset as [`scoped-jsx`](https://github.com/eps1lon/types-react-codemod#scoped-jsx)
579579

580580
A long-time request is to remove the global `JSX` namespace from our types in favor of `React.JSX`. This helps prevent pollution of global types which prevents conflicts between different UI libraries that leverage JSX.
@@ -629,7 +629,7 @@ const reducer = (state: State, action: Action) => state;
629629

630630
## Changlog {/*changelog*/}
631631

632-
### Other Breaking Changes {/*other-breaking-changes*/}
632+
### Other breaking changes {/*other-breaking-changes*/}
633633

634634
- **react-dom**: Error for javascript URLs in src/href [#26507](https://github.com/facebook/react/pull/26507)
635635
- **react-dom**: Remove `errorInfo.digest` from `onRecoverableError` [#28222](https://github.com/facebook/react/pull/28222)
@@ -639,7 +639,7 @@ const reducer = (state: State, action: Action) => state;
639639
- **react-dom**: Remove `unstable_runWithPrioirty` [#28271](https://github.com/facebook/react/pull/28271)
640640
- **react-is**: Remove deprecated methods from `react-is` [28224](https://github.com/facebook/react/pull/28224)
641641

642-
### Other Notable Changes {/*other-notable-changes*/}
642+
### Other notable changes {/*other-notable-changes*/}
643643

644644
- **react**: Batch sync, default and continuous lanes [#25700](https://github.com/facebook/react/pull/25700)
645645
- **react**: Don't prerender siblings of suspended component [#26380](https://github.com/facebook/react/pull/26380)

src/content/blog/2024/04/25/react-19.md

+32-38
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ In our [React 19 Beta Upgrade Guide](/blog/2024/04/25/react-19-upgrade-guide), w
2222

2323
- [What's new in React 19](#whats-new-in-react-19)
2424
- [Improvements in React 19](#improvements-in-react-19)
25-
- [How to Upgrade](#how-to-upgrade)
25+
- [How to upgrade](#how-to-upgrade)
2626

2727
For a list of breaking changes, see the [Upgrade Guide](/blog/2024/04/25/react-19-upgrade-guide).
2828

@@ -115,7 +115,7 @@ Actions automatically manage submitting data for you:
115115

116116
</Note>
117117

118-
Building on top of Actions, we're also introducing [`<form>` Actions](#form-actions) to manage forms automatically, [`useOptimistic`](#new-hook-optimistic-updates) to manage optimistic updates, and new hooks [`useActionState`](#new-hook-useactionstate), [`useFormStatus`](#new-hook-useformstatus) hooks to support the common cases for Actions and Forms.
118+
Building on top of Actions, we're also introducing [`<form>` Actions](#form-actions) to manage forms automatically, [`useOptimistic`](#new-hook-optimistic-updates) to manage optimistic updates, and new hooks [`useActionState`](#new-hook-useactionstate), [`useFormStatus`](#new-hook-useformstatus) to support the common cases for Actions and Forms.
119119

120120
In React 19, the above example can be simplified to:
121121

@@ -144,7 +144,7 @@ function ChangeName({ name, setName }) {
144144

145145
In the next section, we'll break down each of the new Action features in React 19.
146146

147-
### New Hook: `useActionState` {/*new-hook-useactionstate*/}
147+
### New hook: `useActionState` {/*new-hook-useactionstate*/}
148148

149149
To make the common cases easier for Actions, we've added a new hook called `useActionState`:
150150

@@ -185,7 +185,7 @@ When a `<form>` Action succeeds, React will automatically reset the form for unc
185185

186186
For more information, see the docs for [`<form>`](/reference/react-dom/components/form), [`<input>`](/reference/react-dom/components/input), and [`<button>`](/reference/react-dom/components/button).
187187

188-
### New Hook: `useFormStatus` {/*new-hook-useformstatus*/}
188+
### New hook: `useFormStatus` {/*new-hook-useformstatus*/}
189189

190190
In design systems, it's common to write design components that need access to information about the `<form>` they're in, without drilling props down to the component. This can be done via Context, but to make the common case easier, we've added a new hook `useFormStatus`:
191191

@@ -200,7 +200,7 @@ function DesignButton() {
200200

201201
For more information, see the docs for [`useFormStatus`](/reference/react-dom/hooks/useFormStatus).
202202

203-
### New Hook: `useOptimistic` {/*new-hook-optimistic-updates*/}
203+
### New hook: `useOptimistic` {/*new-hook-optimistic-updates*/}
204204

205205
Another common UI pattern when performing a data mutation is to show the final state optimistically while the async request is underway. In React 19, we're adding a new hook called `useOptimistic` to make this easier:
206206

@@ -272,7 +272,7 @@ To fix, you need to pass a promise from a suspense powered library or framework
272272

273273
</Note>
274274

275-
You can also read context with `use`, allowing you to react Context conditionally:
275+
You can also read context with `use`, allowing you to read Context conditionally:
276276

277277
```js {1,8,10}
278278
import {use} from 'react';
@@ -364,7 +364,7 @@ New function components will no longer need `forwardRef`, and we will be publish
364364

365365
</Note>
366366

367-
### Diffs for Hydration Errors {/*diffs-for-hydration-errors*/}
367+
### Diffs for hydration errors {/*diffs-for-hydration-errors*/}
368368

369369
We also improved error reporting for hydration errors. For example, instead of logging multiple errors in DEV without any information about the mismatch:
370370

@@ -457,7 +457,7 @@ New Context providers can use `<Context>` and we will be publishing a codemod to
457457

458458
We now support returning a cleanup function from `ref` callbacks:
459459

460-
```js {7-11}
460+
```js {7-9}
461461
<input
462462
ref={(ref) => {
463463
// ref created
@@ -481,21 +481,19 @@ In future versions, we will deprecate calling refs with `null` when unmounting c
481481

482482
</Note>
483483

484-
Due to the introduction of ref cleanup functions, returning anything else from a `ref` callback will now be rejected by TypeScript.
484+
Due to the introduction of ref cleanup functions, returning anything else from a `ref` callback will now be rejected by TypeScript. The fix is usually to stop using implicit returns, for example:
485485

486-
The fix is usually to stop using implicit returns, for example:
487-
488-
```diff
489-
-<div ref={current => (instance = current)} />
490-
+<div ref={current => {instance = current}} />
486+
```diff [[1, 1, "("], [1, 1, ")"], [2, 2, "{", 15], [2, 2, "}", 1]]
487+
- <div ref={current => (instance = current)} />
488+
+ <div ref={current => {instance = current}} />
491489
```
492490

493491
The original code returned the instance of the `HTMLDivElement` and TypeScript wouldn't know if this was _supposed_ to be a cleanup function or if you didn't want to return a cleanup function.
494492

495493
You can codemod this pattern with [`no-implicit-ref-callback-return
496494
`](https://github.com/eps1lon/types-react-codemod/#no-implicit-ref-callback-return).
497495

498-
### `useDeferredValue` inital value {/*use-deferred-value-initial-value*/}
496+
### `useDeferredValue` initial value {/*use-deferred-value-initial-value*/}
499497

500498
We've added an `initalValue` option to `useDeferredValue`:
501499

@@ -521,7 +519,7 @@ In HTML, document metadata tags like `<title>`, `<link>`, and `<meta>` are reser
521519

522520
In React 19, we're adding support for rendering document metadata tags in components natively:
523521
524-
```js {5,6}
522+
```js {5-8}
525523
function BlogPost({post}) {
526524
return (
527525
<article>
@@ -556,14 +554,14 @@ Stylesheets, both externally linked (`<link rel="stylesheet" href="...">`) and i
556554

557555
In React 19, we're addressing this complexity and providing even deeper integration into Concurrent Rendering on the Client and Streaming Rendering on the Server with built in support for stylesheets. If you tell React the `precedence` of your stylesheet it will manage the insertion order of the stylesheet in the DOM and ensure that the stylesheet (if external) is loaded before revealing content that depends on those style rules.
558556
559-
```js
557+
```js {4,5,17}
560558
function ComponentOne() {
561559
return (
562560
<Suspense fallback="loading...">
563561
<link rel="stylesheet" href="foo" precedence="default" />
564562
<link rel="stylesheet" href="bar" precedence="high" />
565563
<article class="foo-class bar-class">
566-
High from ComponentOne
564+
{...}
567565
</article>
568566
</Suspense>
569567
)
@@ -572,7 +570,7 @@ function ComponentOne() {
572570
function ComponentTwo() {
573571
return (
574572
<div>
575-
Hi from ComponentTwo
573+
<p>{...}</p>
576574
<link rel="stylesheet" href="baz" precedence="default" /> <-- will be inserted between foo & bar
577575
</div>
578576
)
@@ -581,10 +579,9 @@ function ComponentTwo() {
581579
582580
During Server Side Rendering React will include the stylesheet in the `<head>`, which ensures that the browser will not paint until it has loaded. If the stylesheet is discovered late after we've already started streaming, React will ensure that the stylesheet is inserted into the `<head>` on the client before revealing the content of a Suspense boundary that depends on that stylesheet.
583581

584-
During Client Side Rendering React will wait for newly rendered stylesheets to load before committing the render.
582+
During Client Side Rendering React will wait for newly rendered stylesheets to load before committing the render. If you render this component from multiple places within your application React will only include the stylesheet once in the document:
585583

586-
If you render this component from multiple places within your application React will only include the stylesheet once in the document:
587-
```js
584+
```js {5}
588585
function App() {
589586
return <>
590587
<ComponentOne />
@@ -596,7 +593,7 @@ function App() {
596593

597594
For users accustomed to loading stylesheets manually this is an opportunity to locate those stylesheets alongside the components that depend on them allowing for better local reasoning and an easier time ensuring you only load the stylesheets that you actually depend on.
598595

599-
style libraries and style integrations with bundlers can also adopt this new capability so even if you don't directly render your own stylesheets, you can still benefit as your tools are upgraded to use this feature.
596+
Style libraries and style integrations with bundlers can also adopt this new capability so even if you don't directly render your own stylesheets, you can still benefit as your tools are upgraded to use this feature.
600597
601598
For more details, read the docs for [`<link>`](/reference/react-dom/components/link) and [`<style>`](/reference/react-dom/components/style).
602599
@@ -606,7 +603,7 @@ In HTML normal scripts (`<script src="...">`) and deferred scripts (`<script def
606603
607604
In React 19 we've included better support for async scripts by allowing you to render them anywhere in your component tree, inside the components that actually depend on the script, without having to manage relocating and deduplicating script instances.
608605

609-
```js
606+
```js {4,15}
610607
function MyComponent() {
611608
return (
612609
<div>
@@ -627,9 +624,9 @@ function App() {
627624
}
628625
```
629626

630-
In all rendering environments async scripts will be deduplicated so that React will only load and execute the script once even if it is rendered by multiple different components.
627+
In all rendering environments, async scripts will be deduplicated so that React will only load and execute the script once even if it is rendered by multiple different components.
631628

632-
In Server Side Rendering async scripts will be included in the `<head>` and prioritized behind more critical resources that block paint such as stylesheets, fonts, and image preloads.
629+
In Server Side Rendering, async scripts will be included in the `<head>` and prioritized behind more critical resources that block paint such as stylesheets, fonts, and image preloads.
633630

634631
For more details, read the docs for [`<script>`](/reference/react-dom/components/script).
635632

@@ -666,9 +663,7 @@ function MyComponent() {
666663
</html>
667664
```
668665
669-
These APIs can be used to make initial page loads optimized for instance by moving discovery of additional resources like fonts out of stylesheet loading
670-
671-
These APIs can be used to make client updates faster for instance by prefetching a list of resources used by an anticipated navigation and then eagerly preloading those resources on click or even on hover.
666+
These APIs can be used to optimize initial page loads by moving discovery of additional resources like fonts out of stylesheet loading. They can also make client updates faster by prefetching a list of resources used by an anticipated navigation and then eagerly preloading those resources on click or even on hover.
672667
673668
For more details see [Resource Preloading APIs](/reference/react-dom#resource-preloading-apis).
674669
@@ -678,9 +673,9 @@ We've improved hydration to account for third-party scripts and browser extensio
678673
679674
When hydrating, if an element that renders on the client doesn't match the element found in the HTML from the server, React will force a client re-render to fix up the content. Previously, if an element was inserted by third-party scripts or browser extensions, it would trigger a mismatch error and client render.
680675
681-
In React 19 unexpected tags in the `<head>` and `<body>` will be skipped over, avoiding the mismatch errors. If React needs to re-render the entire document due to an unrelated hydration mismatch, it will leave in place stylesheets inserted by third-party scripts and browser extensions.
676+
In React 19, unexpected tags in the `<head>` and `<body>` will be skipped over, avoiding the mismatch errors. If React needs to re-render the entire document due to an unrelated hydration mismatch, it will leave in place stylesheets inserted by third-party scripts and browser extensions.
682677
683-
### Better Error Reporting {/*error-handling*/}
678+
### Better error reporting {/*error-handling*/}
684679
685680
We improved error handling in React 19 to remove duplication and provide options for handling caught and uncaught errors. For example, when there's an error in render caught by an Error Boundary, previously React would throw the error twice (once for the original error, then again after failing to automatically recover), and then call `console.error` with info about where the error occurred.
686681
@@ -748,20 +743,19 @@ Additionally, we've added two new root options to complement `onRecoverableError
748743
749744
For more info and examples, see the docs for [`createRoot`](/reference/react-dom/client/createRoot) and [`hydrateRoot`](/reference/react-dom/client/hydrateRoot).
750745
751-
### Custom Element Support {/*support-for-web-components*/}
752-
753-
Custom Elements have been part of the web platform for a long while now, however using them with React has been impractical because React has always treated unrecognized props as attributes rather than properties.
746+
### Support for Custom Elements {/*support-for-custom-elements*/}
754747
755-
React 19 adds support for custom elements and passes all tests on [Custom Elements Everywhere](https://custom-elements-everywhere.com/).
748+
React 19 adds full support for custom elements and passes all tests on [Custom Elements Everywhere](https://custom-elements-everywhere.com/).
756749
757-
During Server Side Rendering props passed to a custom element will render as attributes if their type is a `"string"`, `"number"`, or the value is `true`. Props with type `"object"`, `"symbol"`, `"function"`, or value `false` will be omitted.
750+
In past versions, using Custom Elements in React has been difficult because React treated unrecognized props as attributes rather than properties. In React 19, we've added support for properties that works on the client and during SSR with the following strategy:
758751
759-
During Client Side Rendering props that match a property on the Custom Element instance will be assigned as properties, otherwise they will be assigned as attributes.
752+
- **Server Side Rendering**: props passed to a custom element will render as attributes if their type is a primitive value like `string`, `number`, or the value is `true`. Props with non-primitive types like `object`, `symbol`, `function`, or value `false` will be omitted.
753+
- **Client Side Rendering**: props that match a property on the Custom Element instance will be assigned as properties, otherwise they will be assigned as attributes.
760754

761755
Thanks to [Joey Arhar](https://github.com/josepharhar) for driving the design and implementation of Custom Element support in React.
762756

763757

764-
#### How to Upgrade {/*how-to-upgrade*/}
758+
#### How to upgrade {/*how-to-upgrade*/}
765759
See the [React 19 Upgrade Guide](/blog/2024/04/25/react-19-upgrade-guide) for step-by-step instructions and a full list of breaking and notable changes.
766760

767761

0 commit comments

Comments
 (0)