Skip to content

Commit 36e8e7b

Browse files
authored
Merge pull request #335 from reactjs/sync-4f9e9a56
Sync with react.dev @ 4f9e9a5
2 parents 4bbc09c + 48fd7b3 commit 36e8e7b

File tree

77 files changed

+2859
-311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+2859
-311
lines changed

.env.production

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
NEXT_PUBLIC_GA_TRACKING_ID = 'UA-41298772-4'
1+
NEXT_PUBLIC_GA_TRACKING_ID = 'G-B1E83PJ3RT'

package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@
3030
"classnames": "^2.2.6",
3131
"date-fns": "^2.16.1",
3232
"debounce": "^1.2.1",
33-
"ga-lite": "^2.1.4",
3433
"github-slugger": "^1.3.0",
3534
"next": "^13.4.1",
3635
"next-remote-watch": "^1.0.0",
3736
"parse-numeric-range": "^1.2.0",
3837
"react": "^0.0.0-experimental-16d053d59-20230506",
39-
"react-collapsed": "npm:@gaearon/[email protected]",
38+
"react-collapsed": "4.0.4",
4039
"react-dom": "^0.0.0-experimental-16d053d59-20230506",
4140
"remark-frontmatter": "^4.0.1",
4241
"remark-gfm": "^3.0.1"
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
11.7 KB
Loading
12.3 KB
Loading
Loading
Loading
Loading
Loading

src/components/Layout/Feedback.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import {useState} from 'react';
66
import {useRouter} from 'next/router';
7-
import {ga} from '../../utils/analytics';
87

98
export function Feedback({onSubmit = () => {}}: {onSubmit?: () => void}) {
109
const {asPath} = useRouter();
@@ -46,16 +45,16 @@ const thumbsDownIcon = (
4645
);
4746

4847
function sendGAEvent(isPositive: boolean) {
48+
const category = isPositive ? 'like_button' : 'dislike_button';
49+
const value = isPositive ? 1 : 0;
4950
// Fragile. Don't change unless you've tested the network payload
5051
// and verified that the right events actually show up in GA.
51-
ga(
52-
'send',
53-
'event',
54-
'button',
55-
'feedback',
56-
window.location.pathname,
57-
isPositive ? '1' : '0'
58-
);
52+
// @ts-ignore
53+
gtag('event', 'feedback', {
54+
event_category: category,
55+
event_label: window.location.pathname,
56+
event_value: value,
57+
});
5958
}
6059

6160
function SendFeedback({onSubmit}: {onSubmit: () => void}) {

src/components/Layout/Page.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,12 @@ interface PageProps {
2828
children: React.ReactNode;
2929
toc: Array<TocItem>;
3030
routeTree: RouteItem;
31-
meta: {title?: string; canary?: boolean; description?: string};
31+
meta: {
32+
title?: string;
33+
titleForTitleTag?: string;
34+
canary?: boolean;
35+
description?: string;
36+
};
3237
section: 'learn' | 'reference' | 'community' | 'blog' | 'home' | 'unknown';
3338
}
3439

@@ -107,6 +112,7 @@ export function Page({children, toc, routeTree, meta, section}: PageProps) {
107112
<>
108113
<Seo
109114
title={title}
115+
titleForTitleTag={meta.titleForTitleTag}
110116
isHomePage={isHomePage}
111117
image={`/images/og-` + section + '.png'}
112118
searchOrder={searchOrder}

src/components/Layout/Sidebar/SidebarLink.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export function SidebarLink({
7777
{title}{' '}
7878
{canary && (
7979
<IconCanary
80-
title="This feature is available in the latest Canary"
80+
title=" - This feature is available in the latest Canary"
8181
className="ms-2 text-gray-30 dark:text-gray-60 inline-block w-4 h-4 align-[-3px]"
8282
/>
8383
)}

src/components/Layout/Sidebar/SidebarRouteTree.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {useRef, useLayoutEffect, Fragment} from 'react';
77
import cn from 'classnames';
88
import {useRouter} from 'next/router';
99
import {SidebarLink} from './SidebarLink';
10-
import useCollapse from 'react-collapsed';
10+
import {useCollapse} from 'react-collapsed';
1111
import usePendingRoute from 'hooks/usePendingRoute';
1212
import type {RouteItem} from 'components/Layout/getRouteMeta';
1313

src/components/Layout/getRouteMeta.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ export interface RouteMeta {
5858
order?: number;
5959
}
6060

61-
type TravesalContext = RouteMeta & {
61+
type TraversalContext = RouteMeta & {
6262
currentIndex: number;
6363
};
6464

6565
export function getRouteMeta(cleanedPath: string, routeTree: RouteItem) {
6666
const breadcrumbs = getBreadcrumbs(cleanedPath, routeTree);
67-
const ctx: TravesalContext = {
67+
const ctx: TraversalContext = {
6868
currentIndex: 0,
6969
};
7070
buildRouteMeta(cleanedPath, routeTree, ctx);
@@ -79,7 +79,7 @@ export function getRouteMeta(cleanedPath: string, routeTree: RouteItem) {
7979
function buildRouteMeta(
8080
searchPath: string,
8181
currentRoute: RouteItem,
82-
ctx: TravesalContext
82+
ctx: TraversalContext
8383
) {
8484
ctx.currentIndex++;
8585

src/components/MDX/MDXComponents.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ function Illustration({
243243
src={src}
244244
alt={alt}
245245
style={{maxHeight: 300}}
246-
className="bg-white rounded-lg"
246+
className="rounded-lg"
247247
/>
248248
{caption ? (
249249
<figcaption className="text-center leading-tight mt-4">
@@ -275,7 +275,12 @@ function IllustrationBlock({
275275
const images = imageInfos.map((info, index) => (
276276
<figure key={index}>
277277
<div className="bg-white rounded-lg p-4 flex-1 flex xl:p-6 justify-center items-center my-4">
278-
<img src={info.src} alt={info.alt} height={info.height} />
278+
<img
279+
className="text-primary"
280+
src={info.src}
281+
alt={info.alt}
282+
height={info.height}
283+
/>
279284
</div>
280285
{info.caption ? (
281286
<figcaption className="text-secondary dark:text-secondary-dark text-center leading-tight mt-4">

src/components/MDX/Sandpack/Preview.tsx

+6
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ export function Preview({
5252
rawError = null;
5353
}
5454

55+
// When throwing a new Error in Sandpack - we want to disable the dev error dialog
56+
// to show the Error Boundary fallback
57+
if (rawError && rawError.message.includes(`throw Error('Example error')`)) {
58+
rawError = null;
59+
}
60+
5561
// Memoized because it's fed to debouncing.
5662
const firstLintError = useMemo(() => {
5763
if (lintErrors.length === 0) {

src/components/PageHeading.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function PageHeading({
3434
{title}
3535
{canary && (
3636
<IconCanary
37-
title="This feature is available in the latest Canary"
37+
title=" - This feature is available in the latest Canary"
3838
className="ms-4 mt-1 text-gray-50 dark:text-gray-40 inline-block w-6 h-6 align-[-1px]"
3939
/>
4040
)}

src/components/Seo.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {siteConfig} from '../siteConfig';
99

1010
export interface SeoProps {
1111
title: string;
12+
titleForTitleTag: undefined | string;
1213
description?: string;
1314
image?: string;
1415
// jsonld?: JsonLDType | Array<JsonLDType>;
@@ -22,6 +23,7 @@ const deployedTranslations = [
2223
'zh-hans',
2324
'es',
2425
'fr',
26+
'ja',
2527
// We'll add more languages when they have enough content.
2628
// Please DO NOT edit this list without a discussion in the reactjs/react.dev repo.
2729
// It must be the same between all translations.
@@ -35,7 +37,7 @@ function getDomain(languageCode: string): string {
3537
export const Seo = withRouter(
3638
({
3739
title,
38-
description = 'The library for web and native user interfaces',
40+
titleForTitleTag,
3941
image = '/images/og-default.png',
4042
router,
4143
children,
@@ -46,14 +48,20 @@ export const Seo = withRouter(
4648
const canonicalUrl = `https://${siteDomain}${
4749
router.asPath.split(/[\?\#]/)[0]
4850
}`;
49-
const pageTitle = isHomePage ? title : title + ' – React';
51+
// Allow setting a different title for Google results
52+
const pageTitle =
53+
(titleForTitleTag ?? title) + (isHomePage ? '' : ' – React');
5054
// Twitter's meta parser is not very good.
5155
const twitterTitle = pageTitle.replace(/[<>]/g, '');
56+
let description = isHomePage
57+
? 'React is the library for web and native user interfaces. Build user interfaces out of individual pieces called components written in JavaScript. React is designed to let you seamlessly combine components written by independent people, teams, and organizations.'
58+
: 'The library for web and native user interfaces';
5259
return (
5360
<Head>
5461
<meta name="viewport" content="width=device-width, initial-scale=1" />
5562
{title != null && <title key="title">{pageTitle}</title>}
56-
{description != null && (
63+
{isHomePage && (
64+
// Let Google figure out a good description for each page.
5765
<meta name="description" key="description" content={description} />
5866
)}
5967
<link rel="canonical" href={canonicalUrl} />

src/content/blog/2022/03/08/react-18-upgrade-guide.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ For more information, see the [Automatic batching deep dive](https://github.com/
224224

225225
In the React 18 Working Group we worked with library maintainers to create new APIs needed to support concurrent rendering for use cases specific to their use case in areas like styles, and external stores. To support React 18, some libraries may need to switch to one of the following APIs:
226226

227-
* `useSyncExternalStore` is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. This new API is recommended for any library that integrates with state external to React. For more information, see the [useSyncExternalStore overview post](https://github.com/reactwg/react-18/discussions/70) and [useSyncExternalStore API details](https://github.com/reactwg/react-18/discussions/86).
228-
* `useInsertionEffect` is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you've already built a CSS-in-JS library we don't expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout. For more information, see the [Library Upgrade Guide for `<style>`](https://github.com/reactwg/react-18/discussions/110).
227+
* `useSyncExternalStore` is a new Hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. This new API is recommended for any library that integrates with state external to React. For more information, see the [useSyncExternalStore overview post](https://github.com/reactwg/react-18/discussions/70) and [useSyncExternalStore API details](https://github.com/reactwg/react-18/discussions/86).
228+
* `useInsertionEffect` is a new Hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you've already built a CSS-in-JS library we don't expect you to ever use this. This Hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout. For more information, see the [Library Upgrade Guide for `<style>`](https://github.com/reactwg/react-18/discussions/110).
229229

230230
React 18 also introduces new APIs for concurrent rendering such as `startTransition`, `useDeferredValue` and `useId`, which we share more about in the [release post](/blog/2022/03/29/react-v18).
231231

src/content/blog/2022/03/29/react-v18.md

+5-6
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ startTransition(() => {
139139
Updates wrapped in startTransition are handled as non-urgent and will be interrupted if more urgent updates like clicks or key presses come in. If a transition gets interrupted by the user (for example, by typing multiple characters in a row), React will throw out the stale rendering work that wasn’t finished and render only the latest update.
140140

141141

142-
* `useTransition`: a hook to start transitions, including a value to track the pending state.
143-
* `startTransition`: a method to start transitions when the hook cannot be used.
142+
* `useTransition`: a Hook to start transitions, including a value to track the pending state.
143+
* `startTransition`: a method to start transitions when the Hook cannot be used.
144144

145145
Transitions will opt in to concurrent rendering, which allows the update to be interrupted. If the content re-suspends, transitions also tell React to continue showing the current content while rendering the transition content in the background (see the [Suspense RFC](https://github.com/reactjs/rfcs/blob/main/text/0213-suspense-in-react-18.md) for more info).
146146

@@ -229,7 +229,7 @@ With Strict Mode in React 18, React will simulate unmounting and remounting the
229229

230230
#### useId {/*useid*/}
231231

232-
`useId` is a new hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but it's even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order. [See docs here](/reference/react/useId).
232+
`useId` is a new Hook for generating unique IDs on both the client and server, while avoiding hydration mismatches. It is primarily useful for component libraries integrating with accessibility APIs that require unique IDs. This solves an issue that already exists in React 17 and below, but it's even more important in React 18 because of how the new streaming server renderer delivers HTML out-of-order. [See docs here](/reference/react/useId).
233233

234234
> Note
235235
>
@@ -245,15 +245,15 @@ With Strict Mode in React 18, React will simulate unmounting and remounting the
245245

246246
#### useSyncExternalStore {/*usesyncexternalstore*/}
247247

248-
`useSyncExternalStore` is a new hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. It removes the need for useEffect when implementing subscriptions to external data sources, and is recommended for any library that integrates with state external to React. [See docs here](/reference/react/useSyncExternalStore).
248+
`useSyncExternalStore` is a new Hook that allows external stores to support concurrent reads by forcing updates to the store to be synchronous. It removes the need for useEffect when implementing subscriptions to external data sources, and is recommended for any library that integrates with state external to React. [See docs here](/reference/react/useSyncExternalStore).
249249

250250
> Note
251251
>
252252
> `useSyncExternalStore` is intended to be used by libraries, not application code.
253253
254254
#### useInsertionEffect {/*useinsertioneffect*/}
255255

256-
`useInsertionEffect` is a new hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you’ve already built a CSS-in-JS library we don’t expect you to ever use this. This hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout. [See docs here](/reference/react/useInsertionEffect).
256+
`useInsertionEffect` is a new Hook that allows CSS-in-JS libraries to address performance issues of injecting styles in render. Unless you’ve already built a CSS-in-JS library we don’t expect you to ever use this. This Hook will run after the DOM is mutated, but before layout effects read the new layout. This solves an issue that already exists in React 17 and below, but is even more important in React 18 because React yields to the browser during concurrent rendering, giving it a chance to recalculate layout. [See docs here](/reference/react/useInsertionEffect).
257257

258258
> Note
259259
>
@@ -339,4 +339,3 @@ See [How to Upgrade to React 18](/blog/2022/03/08/react-18-upgrade-guide) for st
339339
* Update webpack plugin for webpack 5 ([#22739](https://github.com/facebook/react/pull/22739) by [@michenly](https://github.com/michenly))
340340
* Fix a mistake in the Node loader. ([#22537](https://github.com/facebook/react/pull/22537) by [@btea](https://github.com/btea))
341341
* Use `globalThis` instead of `window` for edge environments. ([#22777](https://github.com/facebook/react/pull/22777) by [@huozhi](https://github.com/huozhi))
342-

src/content/blog/2022/06/15/react-labs-what-we-have-been-working-on-june-2022.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ June 15, 2022 by [Andrew Clark](https://twitter.com/acdlite), [Dan Abramov](http
88

99
<Intro>
1010

11-
[React 18](https://reactjs.org/blog/2022/03/29/react-v18) was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re exploring.
11+
[React 18](https://react.dev/blog/2022/03/29/react-v18) was years in the making, and with it brought valuable lessons for the React team. Its release was the result of many years of research and exploring many paths. Some of those paths were successful; many more were dead-ends that led to new insights. One lesson we’ve learned is that it’s frustrating for the community to wait for new features without having insight into these paths that we’re exploring.
1212

1313
</Intro>
1414

@@ -28,7 +28,7 @@ We’re working together with Vercel and Shopify to unify bundler support for sh
2828

2929
## Asset Loading {/*asset-loading*/}
3030

31-
Currently, assets like scripts, external styles, fonts, and images are typically preloaded and loaded using external systems. This can make it tricky to coordinate across new environments like streaming, server components, and more.
31+
Currently, assets like scripts, external styles, fonts, and images are typically preloaded and loaded using external systems. This can make it tricky to coordinate across new environments like streaming, Server Components, and more.
3232
We’re looking at adding APIs to preload and load deduplicated external assets through React APIs that work in all React environments.
3333

3434
We’re also looking at having these support Suspense so you can have images, CSS, and fonts that block display until they’re loaded but don’t block streaming and concurrent rendering. This can help avoid [“popcorning“](https://twitter.com/sebmarkbage/status/1516852731251724293) as the visuals pop and layout shifts.
@@ -41,7 +41,7 @@ Static Site Generation (SSG) and Incremental Static Regeneration (ISR) are great
4141

4242
We gave an [early preview](https://www.youtube.com/watch?v=lGEMwh32soc) of React Forget at React Conf 2021. It’s a compiler that automatically generates the equivalent of `useMemo` and `useCallback` calls to minimize the cost of re-rendering, while retaining React’s programming model.
4343

44-
Recently, we finished a rewrite of the compiler to make it more reliable and capable. This new architecture allows us to analyze and memoize more complex patterns such as the use of [local mutations](/learn/keeping-components-pure#local-mutation-your-components-little-secret), and opens up many new compile-time optimization opportunities beyond just being on par with memoization hooks.
44+
Recently, we finished a rewrite of the compiler to make it more reliable and capable. This new architecture allows us to analyze and memoize more complex patterns such as the use of [local mutations](/learn/keeping-components-pure#local-mutation-your-components-little-secret), and opens up many new compile-time optimization opportunities beyond just being on par with memoization Hooks.
4545

4646
We’re also working on a playground for exploring many aspects of the compiler. While the goal of the playground is to make development of the compiler easier, we think that it will make it easier to try it out and build intuition for what the compiler does. It reveals various insights into how it works under the hood, and live renders the compiler’s outputs as you type. This will be shipped together with the compiler when it’s released.
4747

0 commit comments

Comments
 (0)