Skip to content

Commit e1c6ee2

Browse files
authored
Merge pull request #468 from reactjs/sync-a3e9466d
Sync with react.dev @ a3e9466
2 parents f59fcf5 + f84fc42 commit e1c6ee2

35 files changed

+18297
-108
lines changed

next-env.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3-
/// <reference types="next/navigation-types/compat/navigation" />
43

54
// NOTE: This file should not be edited
6-
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
5+
// see https://nextjs.org/docs/pages/api-reference/config/typescript for more information.
Loading
Loading
Binary file not shown.
Loading
Binary file not shown.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*/
4+
5+
import {memo} from 'react';
6+
7+
export const IconExperimental = memo<
8+
JSX.IntrinsicElements['svg'] & {title?: string; size?: 's' | 'md'}
9+
>(function IconCanary(
10+
{className, title, size} = {
11+
className: undefined,
12+
title: undefined,
13+
size: 'md',
14+
}
15+
) {
16+
return (
17+
<svg
18+
className={className}
19+
width={size === 's' ? '12px' : '20px'}
20+
height={size === 's' ? '12px' : '20px'}
21+
viewBox="0 0 20 20"
22+
version="1.1"
23+
xmlns="http://www.w3.org/2000/svg">
24+
{title && <title>{title}</title>}
25+
<g stroke="none" strokeWidth="1" fill="none" fillRule="evenodd">
26+
<g
27+
id="noun-labs-1201738-(2)"
28+
transform="translate(2, 0)"
29+
fill="currentColor"
30+
fillRule="nonzero">
31+
<path
32+
d="M10.2865804,5.55665262 L10.2865804,2.22331605 L10.8591544,2.22331605 C11.0103911,2.22244799 11.1551447,2.16342155 11.2617505,2.05914367 C11.3684534,1.95486857 11.4282767,1.81370176 11.4282767,1.66667106 L11.4282767,0.556642208 C11.4282767,0.40907262 11.3678934,0.26747526 11.2605218,0.16308627 C11.1531503,0.0587028348 11.0074938,0 10.8556998,0 L5.14338868,0 C4.9915947,0 4.84594391,0.0587028348 4.73856664,0.16308627 C4.63119507,0.267469704 4.57081178,0.40907262 4.57081178,0.556642208 L4.57081178,1.66667106 C4.57081178,1.81434899 4.63119507,1.95594912 4.73856664,2.06033811 C4.8459382,2.16472155 4.9915947,2.22331605 5.14338868,2.22331605 L5.71596273,2.22331605 L5.71596273,5.55665262 C5.71596273,8.38665538 2.97295619,9.88999017 0.651686904,15.5566623 C-0.0957823782,17.360053 -2.00560068,20 7.99951567,20 C18.004632,20 16.0948137,17.3600252 15.3507732,15.5566623 C13.0124432,9.88999017 10.2865804,8.38665538 10.2865804,5.55665262 Z M9.89570197,10.709991 C10.0921412,10.709991 10.2805515,10.7858383 10.4193876,10.9209301 C10.5583466,11.0559135 10.6363652,11.2390693 10.6363652,11.4300417 C10.6363652,11.6210141 10.5583466,11.8040698 10.4193876,11.9391533 C10.2805401,12.0741367 10.0921412,12.1499813 9.89570197,12.1499813 C9.6992627,12.1499813 9.51096673,12.074134 9.37201631,11.9391533 C9.23316875,11.8040615 9.15515307,11.6210141 9.15515307,11.4300417 C9.15515307,11.2390693 9.2331716,11.0559024 9.37201631,10.9209301 C9.57264221,10.7258996 9.61239426,10.709991 9.89570197,10.709991 Z M8.98919546,9.04212824 C9.09790709,9.14792278 9.15884755,9.29158681 9.1585213,9.44110085 C9.15829001,9.59073155 9.09678989,9.73407335 8.98763252,9.83954568 C8.87847514,9.945018 8.73069852,10.0039347 8.57678157,10.0033977 C8.42286747,10.0027392 8.27565088,9.94273467 8.16727355,9.83639845 C8.05900765,9.73006224 7.99873866,9.58628988 7.99963013,9.43664806 C8.00052304,9.28788403 8.0620221,9.14542556 8.17051087,9.04048101 C8.27911107,8.93555591 8.42599335,8.87663641 8.57913312,8.87663641 C8.73291864,8.87665585 8.88047525,8.93622535 8.98919546,9.04212824 Z M7.99965585,17.9999981 C4.91377349,17.9999981 3.29882839,17.7332867 2.51364277,17.4999976 C2.37780966,17.4476975 2.26954376,17.3439641 2.21396931,17.2125528 C2.15838628,17.0811499 2.16006066,16.9334692 2.21876871,16.8033858 C2.6144474,15.5921346 3.14916224,14.4280501 3.81316983,13.3333824 C5.980145,9.82337899 8.22941036,13.8867718 10.0980836,13.8867718 C11.9666996,13.8867718 11.4695868,12.1534924 12.1827971,13.3333824 C12.8511505,14.4269112 13.3916656,15.5896902 13.794259,16.8000524 C13.8533022,16.9322137 13.8537479,17.0822749 13.7952635,17.2147751 C13.7368889,17.3472613 13.6248314,17.4504531 13.4856467,17.5000531 C12.6833967,17.7332867 11.0855382,17.9999981 7.99965585,17.9999981 Z"
33+
id="Shape"></path>
34+
</g>
35+
</g>
36+
</svg>
37+
);
38+
});

src/components/Layout/Page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ interface PageProps {
3131
meta: {
3232
title?: string;
3333
titleForTitleTag?: string;
34-
canary?: boolean;
34+
version?: 'experimental' | 'canary';
3535
description?: string;
3636
};
3737
section: 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown';
@@ -53,7 +53,7 @@ export function Page({
5353
routeTree
5454
);
5555
const title = meta.title || route?.title || '';
56-
const canary = meta.canary || false;
56+
const version = meta.version;
5757
const description = meta.description || route?.description || '';
5858
const isHomePage = cleanedPath === '/';
5959
const isBlogIndex = cleanedPath === '/blog';
@@ -70,7 +70,7 @@ export function Page({
7070
)}>
7171
<PageHeading
7272
title={title}
73-
canary={canary}
73+
version={version}
7474
description={description}
7575
tags={route?.tags}
7676
breadcrumbs={breadcrumbs}

src/components/Layout/Sidebar/SidebarLink.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import * as React from 'react';
99
import cn from 'classnames';
1010
import {IconNavArrow} from 'components/Icon/IconNavArrow';
1111
import {IconCanary} from 'components/Icon/IconCanary';
12+
import {IconExperimental} from 'components/Icon/IconExperimental';
1213
import Link from 'next/link';
1314

1415
interface SidebarLinkProps {
1516
href: string;
1617
selected?: boolean;
1718
title: string;
1819
level: number;
19-
version?: 'canary' | 'major';
20+
version?: 'canary' | 'major' | 'experimental';
2021
icon?: React.ReactNode;
2122
isExpanded?: boolean;
2223
hideArrow?: boolean;
@@ -84,7 +85,13 @@ export function SidebarLink({
8485
)}
8586
{version === 'canary' && (
8687
<IconCanary
87-
title=" - This feature is available in the latest Canary"
88+
title=" - This feature is available in the latest Canary version of React"
89+
className="ms-1 text-gray-30 dark:text-gray-60 inline-block w-3.5 h-3.5 align-[-3px]"
90+
/>
91+
)}
92+
{version === 'experimental' && (
93+
<IconExperimental
94+
title=" - This feature is available in the latest Experimental version of React"
8895
className="ms-1 text-gray-30 dark:text-gray-60 inline-block w-3.5 h-3.5 align-[-3px]"
8996
/>
9097
)}

src/components/MDX/ExpandableCallout.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type CalloutVariants =
1616
| 'note'
1717
| 'wip'
1818
| 'canary'
19+
| 'experimental'
1920
| 'major'
2021
| 'rsc';
2122

@@ -51,6 +52,15 @@ const variantMap = {
5152
overlayGradient:
5253
'linear-gradient(rgba(245, 249, 248, 0), rgba(245, 249, 248, 1)',
5354
},
55+
experimental: {
56+
title: 'Experimental Feature',
57+
Icon: IconCanary,
58+
containerClasses:
59+
'bg-green-5 dark:bg-green-60 dark:bg-opacity-20 text-primary dark:text-primary-dark text-lg',
60+
textColor: 'text-green-60 dark:text-green-40',
61+
overlayGradient:
62+
'linear-gradient(rgba(245, 249, 248, 0), rgba(245, 249, 248, 1)',
63+
},
5464
pitfall: {
5565
title: 'Chú Ý',
5666
Icon: IconPitfall,

src/components/MDX/MDXComponents.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ const Canary = ({children}: {children: React.ReactNode}) => (
9898
<ExpandableCallout type="canary">{children}</ExpandableCallout>
9999
);
100100

101+
const Experimental = ({children}: {children: React.ReactNode}) => (
102+
<ExpandableCallout type="experimental">{children}</ExpandableCallout>
103+
);
104+
101105
const NextMajor = ({children}: {children: React.ReactNode}) => (
102106
<ExpandableCallout type="major">{children}</ExpandableCallout>
103107
);
@@ -120,6 +124,20 @@ const CanaryBadge = ({title}: {title: string}) => (
120124
</span>
121125
);
122126

127+
const ExperimentalBadge = ({title}: {title: string}) => (
128+
<span
129+
title={title}
130+
className={
131+
'text-base font-display px-1 py-0.5 font-bold bg-gray-10 dark:bg-gray-60 text-gray-60 dark:text-gray-10 rounded'
132+
}>
133+
<IconCanary
134+
size="s"
135+
className={'inline me-1 mb-0.5 text-sm text-gray-60 dark:text-gray-10'}
136+
/>
137+
Experimental only
138+
</span>
139+
);
140+
123141
const NextMajorBadge = ({title}: {title: string}) => (
124142
<span
125143
title={title}
@@ -508,6 +526,8 @@ export const MDXComponents = {
508526
MathI,
509527
Note,
510528
Canary,
529+
Experimental,
530+
ExperimentalBadge,
511531
CanaryBadge,
512532
NextMajor,
513533
NextMajorBadge,

src/components/PageHeading.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ import {H1} from './MDX/Heading';
88
import type {RouteTag, RouteItem} from './Layout/getRouteMeta';
99
import * as React from 'react';
1010
import {IconCanary} from './Icon/IconCanary';
11+
import {IconExperimental} from './Icon/IconExperimental';
1112

1213
interface PageHeadingProps {
1314
title: string;
14-
canary?: boolean;
15+
version?: 'experimental' | 'canary';
16+
experimental?: boolean;
1517
status?: string;
1618
description?: string;
1719
tags?: RouteTag[];
@@ -21,19 +23,26 @@ interface PageHeadingProps {
2123
function PageHeading({
2224
title,
2325
status,
24-
canary,
26+
version,
2527
tags = [],
2628
breadcrumbs,
2729
}: PageHeadingProps) {
30+
console.log('version', version);
2831
return (
2932
<div className="px-5 sm:px-12 pt-3.5">
3033
<div className="max-w-4xl ms-0 2xl:mx-auto">
3134
{breadcrumbs ? <Breadcrumbs breadcrumbs={breadcrumbs} /> : null}
3235
<H1 className="mt-0 text-primary dark:text-primary-dark -mx-.5 break-words">
3336
{title}
34-
{canary && (
37+
{version === 'canary' && (
3538
<IconCanary
36-
title=" - This feature is available in the latest Canary"
39+
title=" - This feature is available in the latest Canary version of React"
40+
className="ms-4 mt-1 text-gray-50 dark:text-gray-40 inline-block w-6 h-6 align-[-1px]"
41+
/>
42+
)}
43+
{version === 'experimental' && (
44+
<IconExperimental
45+
title=" - This feature is available in the latest Experimental version of React"
3746
className="ms-4 mt-1 text-gray-50 dark:text-gray-40 inline-block w-6 h-6 align-[-1px]"
3847
/>
3948
)}

src/content/blog/2024/10/21/react-compiler-beta-release.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ October 21, 2024 by [Lauren Tan](https://twitter.com/potetotes).
1010

1111
---
1212

13+
<Note>
14+
15+
### React Compiler is now in RC! {/*react-compiler-is-now-in-rc*/}
16+
17+
Please see the [RC blog post](/blog/2025/04/21/react-compiler-rc) for details.
18+
19+
</Note>
20+
1321
<Intro>
1422

1523
The React team is excited to share new updates:
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: "React Compiler RC"
3+
author: Lauren Tan and Mofei Zhang
4+
date: 2025/04/21
5+
description: We are releasing the compiler's first Release Candidate (RC) today.
6+
7+
---
8+
9+
April 21, 2025 by [Lauren Tan](https://x.com/potetotes) and [Mofei Zhang](https://x.com/zmofei).
10+
11+
---
12+
13+
<Intro>
14+
15+
The React team is excited to share new updates:
16+
17+
</Intro>
18+
19+
1. We're publishing React Compiler RC today, in preparation of the compiler's stable release.
20+
2. We're merging `eslint-plugin-react-compiler` into `eslint-plugin-react-hooks`.
21+
3. We've added support for swc and are working with oxc to support Babel-free builds.
22+
23+
---
24+
25+
[React Compiler](https://react.dev/learn/react-compiler) is a build-time tool that optimizes your React app through automatic memoization. Last year, we published React Compiler’s [first beta](https://react.dev/blog/2024/10/21/react-compiler-beta-release) and received lots of great feedback and contributions. We’re excited about the wins we’ve seen from folks adopting the compiler (see case studies from [Sanity Studio](https://github.com/reactwg/react-compiler/discussions/33) and [Wakelet](https://github.com/reactwg/react-compiler/discussions/52)) and are working towards a stable release.
26+
27+
We are releasing the compiler's first Release Candidate (RC) today. The RC is intended to be a stable and near-final version of the compiler, and safe to try out in production.
28+
29+
## Use React Compiler RC today {/*use-react-compiler-rc-today*/}
30+
To install the RC:
31+
32+
npm
33+
<TerminalBlock>
34+
{`npm install --save-dev --save-exact babel-plugin-react-compiler@rc`}
35+
</TerminalBlock>
36+
37+
pnpm
38+
<TerminalBlock>
39+
{`pnpm add --save-dev --save-exact babel-plugin-react-compiler@rc`}
40+
</TerminalBlock>
41+
42+
yarn
43+
<TerminalBlock>
44+
{`yarn add --dev --exact babel-plugin-react-compiler@rc`}
45+
</TerminalBlock>
46+
47+
As part of the RC, we've been making React Compiler easier to add to your projects and added optimizations to how the compiler generates memoization. React Complier now supports optional chains and array indices as dependencies. We're exploring how to infer even more dependencies like equality checks and string interpolation. These improvements ultimately result in fewer re-renders and more responsive UIs.
48+
49+
We have also heard from the community that the ref-in-render validation sometimes has false positives. Since as a general philosophy we want you to be able to fully trust in the compiler's error messages and hints, we are turning it off by default for now. We will keep working to improve this validation, and we will re-enable it in a follow up release.
50+
51+
You can find more details on using the Compiler in [our docs](https://react.dev/learn/react-compiler).
52+
53+
## Feedback {/*feedback*/}
54+
During the RC period, we encourage all React users to try the compiler and provide feedback in the React repo. Please [open an issue](https://github.com/facebook/react/issues) if you encounter any bugs or unexpected behavior. If you have a general question or suggestion, please post them in the [React Compiler Working Group](https://github.com/reactwg/react-compiler/discussions).
55+
56+
## Backwards Compatibility {/*backwards-compatibility*/}
57+
As noted in the Beta announcement, React Compiler is compatible with React 17 and up. If you are not yet on React 19, you can use React Compiler by specifying a minimum target in your compiler config, and adding `react-compiler-runtime` as a dependency. You can find docs on this [here](https://react.dev/learn/react-compiler#using-react-compiler-with-react-17-or-18).
58+
59+
## Migrating from eslint-plugin-react-compiler to eslint-plugin-react-hooks {/*migrating-from-eslint-plugin-react-compiler-to-eslint-plugin-react-hooks*/}
60+
If you have already installed eslint-plugin-react-compiler, you can now remove it and use `eslint-plugin-react-hooks@6.0.0-rc.1`. Many thanks to [@michaelfaith](https://bsky.app/profile/michael.faith) for contributing to this improvement!
61+
62+
To install:
63+
64+
npm
65+
<TerminalBlock>
66+
{`npm install --save-dev eslint-plugin-react-hooks@6.0.0-rc.1`}
67+
</TerminalBlock>
68+
69+
pnpm
70+
<TerminalBlock>
71+
{`pnpm add --save-dev eslint-plugin-react-hooks@6.0.0-rc.1`}
72+
</TerminalBlock>
73+
74+
yarn
75+
<TerminalBlock>
76+
{`yarn add --dev eslint-plugin-react-hooks@6.0.0-rc.1`}
77+
</TerminalBlock>
78+
79+
```js
80+
// eslint.config.js
81+
import * as reactHooks from 'eslint-plugin-react-hooks';
82+
83+
export default [
84+
// Flat Config (eslint 9+)
85+
reactHooks.configs.recommended,
86+
87+
// Legacy Config
88+
reactHooks.configs['recommended-latest']
89+
];
90+
```
91+
92+
To enable the React Compiler rule, add `'react-hooks/react-compiler': 'error'` to your ESLint configuration.
93+
94+
The linter does not require the compiler to be installed, so there's no risk in upgrading eslint-plugin-react-hooks. We recommend everyone upgrade today.
95+
96+
## swc support (experimental) {/*swc-support-experimental*/}
97+
React Compiler can be installed across [several build tools](/learn/react-compiler#installation) such as Babel, Vite, and Rsbuild.
98+
99+
In addition to those tools, we have been collaborating with Kang Dongyoon ([@kdy1dev](https://x.com/kdy1dev)) from the [swc](https://swc.rs/) team on adding additional support for React Compiler as an swc plugin. While this work isn't done, Next.js build performance should now be considerably faster when the [React Compiler is enabled in your Next.js app](https://nextjs.org/docs/app/api-reference/config/next-config-js/reactCompiler).
100+
101+
We recommend using Next.js [15.3.1](https://github.com/vercel/next.js/releases/tag/v15.3.1) or greater to get the best build performance.
102+
103+
Vite users can continue to use [vite-plugin-react](https://github.com/vitejs/vite-plugin-react) to enable the compiler, by adding it as a [Babel plugin](https://react.dev/learn/react-compiler#usage-with-vite). We are also working with the [oxc](https://oxc.rs/) team to [add support for the compiler](https://github.com/oxc-project/oxc/issues/10048). Once [rolldown](https://github.com/rolldown/rolldown) is officially released and supported in Vite and oxc support is added for React Compiler, we'll update the docs with information on how to migrate.
104+
105+
## Upgrading React Compiler {/*upgrading-react-compiler*/}
106+
React Compiler works best when the auto-memoization applied is strictly for performance. Future versions of the compiler may change how memoization is applied, for example it could become more granular and precise.
107+
108+
However, because product code may sometimes break the [rules of React](https://react.dev/reference/rules) in ways that aren't always statically detectable in JavaScript, changing memoization can occasionally have unexpected results. For example, a previously memoized value might be used as a dependency for a useEffect somewhere in the component tree. Changing how or whether this value is memoized can cause over or under-firing of that useEffect. While we encourage [useEffect only for synchronization](https://react.dev/learn/synchronizing-with-effects), your codebase may have useEffects that cover other use-cases such as effects that needs to only run in response to specific values changing.
109+
110+
In other words, changing memoization may under rare circumstances cause unexpected behavior. For this reason, we recommend following the Rules of React and employing continuous end-to-end testing of your app so you can upgrade the compiler with confidence and identify any rules of React violations that might cause issues.
111+
112+
If you don't have good test coverage, we recommend pinning the compiler to an exact version (eg `19.1.0`) rather than a SemVer range (eg `^19.1.0`). You can do this by passing the `--save-exact` (npm/pnpm) or `--exact` flags (yarn) when upgrading the compiler. You should then do any upgrades of the compiler manually, taking care to check that your app still works as expected.
113+
114+
## Roadmap to Stable {/*roadmap-to-stable*/}
115+
*This is not a final roadmap, and is subject to change.*
116+
117+
After a period of final feedback from the community on the RC, we plan on a Stable Release for the compiler.
118+
119+
* ✅ Experimental: Released at React Conf 2024, primarily for feedback from application developers.
120+
* ✅ Public Beta: Available today, for feedback from library authors.
121+
* ✅ Release Candidate (RC): React Compiler works for the majority of rule-following apps and libraries without issue.
122+
* General Availability: After final feedback period from the community.
123+
124+
Post-Stable, we plan to add more compiler optimizations and improvements. This includes both continual improvements to automatic memoization, and new optimizations altogether, with minimal to no change of product code. Each upgrade will continue to improve performance and add better handling of diverse JavaScript and React patterns.
125+
126+
---
127+
128+
Thanks to [Joe Savona](https://x.com/en_JS), [Jason Bonta](https://x.com/someextent), [Jimmy Lai](https://x.com/feedthejim), and [Kang Dongyoon](https://x.com/kdy1dev) (@kdy1dev) for reviewing and editing this post.

0 commit comments

Comments
 (0)