Skip to content

Commit 280fcfa

Browse files
committed
Merge remote-tracking branch 'reactdev/main' into merge-react-dev
2 parents c51072e + c019eb1 commit 280fcfa

File tree

11 files changed

+58
-301
lines changed

11 files changed

+58
-301
lines changed
Loading
Loading

src/components/Seo.tsx

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import * as React from 'react';
66
import Head from 'next/head';
77
import {withRouter, Router} from 'next/router';
8+
import {siteConfig} from '../siteConfig';
89

910
export interface SeoProps {
1011
title: string;
@@ -16,6 +17,28 @@ export interface SeoProps {
1617
searchOrder?: number;
1718
}
1819

20+
const deployedTranslations = [
21+
'en',
22+
'zh-hans',
23+
'es',
24+
// We'll add more languages when they have enough content.
25+
// Please DO NOT edit this list without a discussion in the reactjs/react.dev repo.
26+
// It must be the same between all translations.
27+
];
28+
29+
let shouldPreventIndexing = false;
30+
if (
31+
siteConfig.languageCode !== 'en' &&
32+
!deployedTranslations.includes(siteConfig.languageCode)
33+
) {
34+
shouldPreventIndexing = true;
35+
}
36+
37+
function getDomain(languageCode: string): string {
38+
const subdomain = languageCode === 'en' ? '' : languageCode + '.';
39+
return subdomain + 'react.dev';
40+
}
41+
1942
export const Seo = withRouter(
2043
({
2144
title,
@@ -26,29 +49,38 @@ export const Seo = withRouter(
2649
isHomePage,
2750
searchOrder,
2851
}: SeoProps & {router: Router}) => {
52+
const siteDomain = getDomain(siteConfig.languageCode);
53+
const canonicalUrl = `https://${siteDomain}${
54+
router.asPath.split(/[\?\#]/)[0]
55+
}`;
2956
const pageTitle = isHomePage ? 'React' : title + ' – React';
3057
// Twitter's meta parser is not very good.
3158
const twitterTitle = pageTitle.replace(/[<>]/g, '');
3259
return (
3360
<Head>
34-
{/* DEFAULT */}
35-
3661
<meta name="viewport" content="width=device-width, initial-scale=1" />
37-
3862
{title != null && <title key="title">{pageTitle}</title>}
3963
{description != null && (
4064
<meta name="description" key="description" content={description} />
4165
)}
42-
{/* <link rel="icon" type="image/x-icon" href={favicon} />
43-
<link rel="apple-touch-icon" href={favicon} /> @todo favicon */}
66+
<link rel="canonical" href={canonicalUrl} />
67+
<link
68+
rel="alternate"
69+
href={canonicalUrl.replace(siteDomain, getDomain('en'))}
70+
hrefLang="x-default"
71+
/>
72+
{shouldPreventIndexing && <meta name="robots" content="noindex" />}
73+
{deployedTranslations.map((languageCode) => (
74+
<link
75+
key={'alt-' + languageCode}
76+
rel="alternate"
77+
hrefLang={languageCode}
78+
href={canonicalUrl.replace(siteDomain, getDomain(languageCode))}
79+
/>
80+
))}
4481
<meta property="fb:app_id" content="623268441017527" />
45-
{/* OPEN GRAPH */}
4682
<meta property="og:type" key="og:type" content="website" />
47-
<meta
48-
property="og:url"
49-
key="og:url"
50-
content={`https://react.dev${router.asPath.split(/[\?\#]/)[0]}`}
51-
/>
83+
<meta property="og:url" key="og:url" content={canonicalUrl} />
5284
{title != null && (
5385
<meta property="og:title" content={pageTitle} key="og:title" />
5486
)}
@@ -59,14 +91,11 @@ export const Seo = withRouter(
5991
content={description}
6092
/>
6193
)}
62-
6394
<meta
6495
property="og:image"
6596
key="og:image"
66-
content={`https://react.dev${image}`}
97+
content={`https://${siteDomain}${image}`}
6798
/>
68-
69-
{/* TWITTER */}
7099
<meta
71100
name="twitter:card"
72101
key="twitter:card"
@@ -88,11 +117,10 @@ export const Seo = withRouter(
88117
content={description}
89118
/>
90119
)}
91-
92120
<meta
93121
name="twitter:image"
94122
key="twitter:image"
95-
content={`https://react.dev${image}`}
123+
content={`https://${siteDomain}${image}`}
96124
/>
97125
<meta
98126
name="google-site-verification"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Offscreen is a low level capability that unlocks high level features. Similar to
6262

6363
## Transition Tracing {/*transition-tracing*/}
6464

65-
Currently, React has two profiling tools. The [original Profiler](https://reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) shows an overview of all the commits in a profiling session. For each commit, it also shows all components that rendered and the amount of time it took for them to render. We also have a beta version of a [Timeline Profiler](https://github.com/reactwg/react-18/discussions/76) introduced in React 18 that shows when components schedule updates and when React works on these updates. Both of these profilers help developers identify performance problems in their code.
65+
Currently, React has two profiling tools. The [original Profiler](https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) shows an overview of all the commits in a profiling session. For each commit, it also shows all components that rendered and the amount of time it took for them to render. We also have a beta version of a [Timeline Profiler](https://github.com/reactwg/react-18/discussions/76) introduced in React 18 that shows when components schedule updates and when React works on these updates. Both of these profilers help developers identify performance problems in their code.
6666

6767
We’ve realized that developers don’t find knowing about individual slow commits or components out of context that useful. It’s more useful to know about what actually causes the slow commits. And that developers want to be able to track specific interactions (eg a button click, an initial load, or a page navigation) to watch for performance regressions and to understand why an interaction was slow and how to fix it.
6868

src/content/community/versioning-policy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Instead, we release new features in minor versions. That means that minor releas
3030

3131
### Commitment to stability {/*commitment-to-stability*/}
3232

33-
As we change React over time, we try to minimize the effort required to take advantage of new features. When possible, we'll keep an older API working, even if that means putting it in a separate package. For example, [mixins have been discouraged for years](/blog/2016/07/13/mixins-considered-harmful.html) but they're supported to this day [via create-react-class](/docs/react-without-es6.html#mixins) and many codebases continue to use them in stable, legacy code.
33+
As we change React over time, we try to minimize the effort required to take advantage of new features. When possible, we'll keep an older API working, even if that means putting it in a separate package. For example, [mixins have been discouraged for years](https://legacy.reactjs.org/blog/2016/07/13/mixins-considered-harmful.html) but they're supported to this day [via create-react-class](https://legacy.reactjs.org/docs/react-without-es6.html#mixins) and many codebases continue to use them in stable, legacy code.
3434

3535
Over a million developers use React, collectively maintaining millions of components. The Facebook codebase alone has over 50,000 React components. That means we need to make it as easy as possible to upgrade to new versions of React; if we make large changes without a migration path, people will be stuck on old versions. We test these upgrade paths on Facebook itself – if our team of less than 10 people can update 50,000+ components alone, we hope the upgrade will be manageable for anyone using React. In many cases, we write [automated scripts](https://github.com/reactjs/react-codemod) to upgrade component syntax, which we then include in the open-source release for everyone to use.
3636

src/content/reference/react/memo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ There is no benefit to wrapping a component in `memo` in other cases. There is n
126126
1. Avoid [unnecessary Effects that update state.](/learn/you-might-not-need-an-effect) Most performance problems in React apps are caused by chains of updates originating from Effects that cause your components to render over and over.
127127
1. Try to [remove unnecessary dependencies from your Effects.](/learn/removing-effect-dependencies) For example, instead of memoization, it's often simpler to move some object or a function inside an Effect or outside the component.
128128

129-
If a specific interaction still feels laggy, [use the React Developer Tools profiler](/blog/2018/09/10/introducing-the-react-profiler.html) to see which components would benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In the long term, we're researching [doing granular memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
129+
If a specific interaction still feels laggy, [use the React Developer Tools profiler](https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) to see which components would benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In the long term, we're researching [doing granular memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
130130

131131
</DeepDive>
132132

src/content/reference/react/useCallback.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ Note that `useCallback` does not prevent *creating* the function. You're always
235235
1. Avoid [unnecessary Effects that update state.](/learn/you-might-not-need-an-effect) Most performance problems in React apps are caused by chains of updates originating from Effects that cause your components to render over and over.
236236
1. Try to [remove unnecessary dependencies from your Effects.](/learn/removing-effect-dependencies) For example, instead of memoization, it's often simpler to move some object or a function inside an Effect or outside the component.
237237
238-
If a specific interaction still feels laggy, [use the React Developer Tools profiler](/blog/2018/09/10/introducing-the-react-profiler.html) to see which components benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In long term, we're researching [doing memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
238+
If a specific interaction still feels laggy, [use the React Developer Tools profiler](https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) to see which components benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In long term, we're researching [doing memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
239239
240240
</DeepDive>
241241

src/content/reference/react/useMemo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ There is no benefit to wrapping a calculation in `useMemo` in other cases. There
161161
1. Avoid [unnecessary Effects that update state.](/learn/you-might-not-need-an-effect) Most performance problems in React apps are caused by chains of updates originating from Effects that cause your components to render over and over.
162162
1. Try to [remove unnecessary dependencies from your Effects.](/learn/removing-effect-dependencies) For example, instead of memoization, it's often simpler to move some object or a function inside an Effect or outside the component.
163163

164-
If a specific interaction still feels laggy, [use the React Developer Tools profiler](/blog/2018/09/10/introducing-the-react-profiler.html) to see which components would benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In the long term, we're researching [doing granular memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
164+
If a specific interaction still feels laggy, [use the React Developer Tools profiler](https://legacy.reactjs.org/blog/2018/09/10/introducing-the-react-profiler.html) to see which components would benefit the most from memoization, and add memoization where needed. These principles make your components easier to debug and understand, so it's good to follow them in any case. In the long term, we're researching [doing granular memoization automatically](https://www.youtube.com/watch?v=lGEMwh32soc) to solve this once and for all.
165165

166166
</DeepDive>
167167

src/pages/_document.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
*/
44

55
import {Html, Head, Main, NextScript} from 'next/document';
6+
import {siteConfig} from '../siteConfig';
67

78
const MyDocument = () => {
8-
// @todo specify language in HTML?
99
return (
10-
<Html lang="en">
10+
<Html lang={siteConfig.languageCode}>
1111
<Head />
1212
<body className="font-text font-medium antialiased text-lg bg-wash dark:bg-wash-dark text-secondary dark:text-secondary-dark leading-base">
1313
<script

src/siteConfig.ts renamed to src/siteConfig.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22
* Copyright (c) Facebook, Inc. and its affiliates.
33
*/
44

5-
export const siteConfig = {
6-
editUrl: 'https://github.com/reactjs/react.dev/tree/main/src/pages',
5+
exports.siteConfig = {
6+
// --------------------------------------
7+
// Translations should replace these lines:
8+
languageCode: 'en',
9+
hasLegacySite: true,
10+
// --------------------------------------
711
copyright: `Copyright © ${new Date().getFullYear()} Facebook Inc. All Rights Reserved.`,
812
repoUrl: 'https://github.com/facebook/react',
913
twitterUrl: 'https://twitter.com/reactjs',

0 commit comments

Comments
 (0)