Skip to content

Commit d02d2e8

Browse files
authored
Merge pull request #922 from reactjs/sync-a8790ca8
Sync with react.dev @ a8790ca
2 parents 6cbc87d + b88c83a commit d02d2e8

Some content is hidden

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

41 files changed

+1750
-230
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
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
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",
Loading
Loading
Loading
Loading

src/components/Layout/Feedback.tsx

+6-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();
@@ -48,14 +47,12 @@ const thumbsDownIcon = (
4847
function sendGAEvent(isPositive: boolean) {
4948
// Fragile. Don't change unless you've tested the network payload
5049
// 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-
);
50+
// @ts-ignore
51+
gtag('event', 'feedback', {
52+
event_category: 'button',
53+
event_label: window.location.pathname,
54+
value: isPositive ? 1 : 0,
55+
});
5956
}
6057

6158
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/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/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/Seo.tsx

+10-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>;
@@ -36,7 +37,7 @@ function getDomain(languageCode: string): string {
3637
export const Seo = withRouter(
3738
({
3839
title,
39-
description = 'The library for web and native user interfaces',
40+
titleForTitleTag,
4041
image = '/images/og-default.png',
4142
router,
4243
children,
@@ -47,14 +48,20 @@ export const Seo = withRouter(
4748
const canonicalUrl = `https://${siteDomain}${
4849
router.asPath.split(/[\?\#]/)[0]
4950
}`;
50-
const pageTitle = isHomePage ? title : title + ' – React';
51+
// Allow setting a different title for Google results
52+
const pageTitle =
53+
(titleForTitleTag ?? title) + (isHomePage ? '' : ' – React');
5154
// Twitter's meta parser is not very good.
5255
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';
5359
return (
5460
<Head>
5561
<meta name="viewport" content="width=device-width, initial-scale=1" />
5662
{title != null && <title key="title">{pageTitle}</title>}
57-
{description != null && (
63+
{isHomePage && (
64+
// Let Google figure out a good description for each page.
5865
<meta name="description" key="description" content={description} />
5966
)}
6067
<link rel="canonical" href={canonicalUrl} />

src/content/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Making plain JavaScript in React components reactive requires a compiler with a
7474

7575
## Offscreen Rendering {/*offscreen-rendering*/}
7676

77-
Offscreen rendering is an upcoming capability in React for rendering screens in the background without additional performance overhead. You can think of it as a version of the [`content-visiblity` CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility) that works not only for DOM elements but React components, too. During our research, we've discovered a variety of use cases:
77+
Offscreen rendering is an upcoming capability in React for rendering screens in the background without additional performance overhead. You can think of it as a version of the [`content-visibility` CSS property](https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility) that works not only for DOM elements but React components, too. During our research, we've discovered a variety of use cases:
7878

7979
- A router can prerender screens in the background so that when a user navigates to them, they're instantly available.
8080
- A tab switching component can preserve the state of hidden tabs, so the user can switch between them without losing their progress.

src/content/learn/describing-the-ui.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -530,13 +530,21 @@ React uses trees to model the relationships between components and modules.
530530

531531
A React render tree is a representation of the parent and child relationship between components.
532532

533-
<Diagram name="generic_render_tree" height={250} width={500} alt="A tree graph with five nodes, with each node representing a component. The root node is located at the top the tree graph and is labelled 'Root Component'. It has two arrows extending down to two nodes labelled 'Component A' and 'Component C'. Each of the arrows is labelled with 'renders'. 'Component A' has a single 'renders' arrow to a node labelled 'Component B'. 'Component C' has a single 'renders' arrow to a node labelled 'Component D'.">An example React render tree.</Diagram>
533+
<Diagram name="generic_render_tree" height={250} width={500} alt="A tree graph with five nodes, with each node representing a component. The root node is located at the top the tree graph and is labelled 'Root Component'. It has two arrows extending down to two nodes labelled 'Component A' and 'Component C'. Each of the arrows is labelled with 'renders'. 'Component A' has a single 'renders' arrow to a node labelled 'Component B'. 'Component C' has a single 'renders' arrow to a node labelled 'Component D'.">
534+
535+
An example React render tree.
536+
537+
</Diagram>
534538

535539
Components near the top of the tree, near the root component, are considered top-level components. Components with no child components are leaf components. This categorization of components is useful for understanding data flow and rendering performance.
536540

537541
Modelling the relationship between JavaScript modules is another useful way to understand your app. We refer to it as a module dependency tree.
538542

539-
<Diagram name="generic_dependency_tree" height={250} width={500} alt="A tree graph with five nodes. Each node represents a JavaScript module. The top-most node is labelled 'RootModule.js'. It has three arrows extending to the nodes: 'ModuleA.js', 'ModuleB.js', and 'ModuleC.js'. Each arrow is labelled as 'imports'. 'ModuleC.js' node has a single 'imports' arrow that points to a node labelled 'ModuleD.js'.">An example module dependency tree.</Diagram>
543+
<Diagram name="generic_dependency_tree" height={250} width={500} alt="A tree graph with five nodes. Each node represents a JavaScript module. The top-most node is labelled 'RootModule.js'. It has three arrows extending to the nodes: 'ModuleA.js', 'ModuleB.js', and 'ModuleC.js'. Each arrow is labelled as 'imports'. 'ModuleC.js' node has a single 'imports' arrow that points to a node labelled 'ModuleD.js'.">
544+
545+
An example module dependency tree.
546+
547+
</Diagram>
540548

541549
A dependency tree is often used by build tools to bundle all the relevant JavaScript code for the client to download and render. A large bundle size regresses user experience for React apps. Understanding the module dependency tree is helpful to debug such issues.
542550

src/content/learn/passing-data-deeply-with-context.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ export const places = [{
985985
}, {
986986
id: 5,
987987
name: 'Chefchaouen, Marocco',
988-
description: 'There are a few theories on why the houses are painted blue, including that the color repells mosquitos or that it symbolizes sky and heaven.',
988+
description: 'There are a few theories on why the houses are painted blue, including that the color repels mosquitos or that it symbolizes sky and heaven.',
989989
imageId: 'rTqKo46'
990990
}, {
991991
id: 6,
@@ -1124,7 +1124,7 @@ export const places = [{
11241124
}, {
11251125
id: 5,
11261126
name: 'Chefchaouen, Marocco',
1127-
description: 'There are a few theories on why the houses are painted blue, including that the color repells mosquitos or that it symbolizes sky and heaven.',
1127+
description: 'There are a few theories on why the houses are painted blue, including that the color repels mosquitos or that it symbolizes sky and heaven.',
11281128
imageId: 'rTqKo46'
11291129
}, {
11301130
id: 6,

src/content/learn/reacting-to-input-with-state.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function submitForm(answer) {
8484
// Pretend it's hitting the network.
8585
return new Promise((resolve, reject) => {
8686
setTimeout(() => {
87-
if (answer.toLowerCase() == 'istanbul') {
87+
if (answer.toLowerCase() === 'istanbul') {
8888
resolve();
8989
} else {
9090
reject(new Error('Good guess but a wrong answer. Try again!'));

src/content/learn/understanding-your-ui-as-a-tree.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ With conditional rendering, across different renders, the render tree may render
253253

254254
In this example, depending on what `inspiration.type` is, we may render `<FancyText>` or `<Color>`. The render tree may be different for each render pass.
255255

256-
Although render trees may differ across render pases, these trees are generally helpful for identifying what the top-level and leaf components are in a React app. Top-level components are the components nearest to the root component and affect the rendering performance of all the components beneath them and often contain the most complexity. Leaf components are near the bottom of the tree and have no child components and are often frequently re-rendered.
256+
Although render trees may differ across render passes, these trees are generally helpful for identifying what the *top-level* and *leaf components* are in a React app. Top-level components are the components nearest to the root component and affect the rendering performance of all the components beneath them and often contain the most complexity. Leaf components are near the bottom of the tree and have no child components and are often frequently re-rendered.
257257

258258
Identifying these categories of components are useful for understanding data flow and performance of your app.
259259

0 commit comments

Comments
 (0)