Skip to content

Commit 8ced164

Browse files
authored
docs(en): merge reactjs.org/main into zh-hans.reactjs.org/main @ eb0ae24
2 parents 6c5e554 + c00817d commit 8ced164

32 files changed

+1196
-1423
lines changed

.github/workflows/analyze.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
node-version: "14.x"
2020

2121
- name: Install dependencies
22-
uses: bahmutov/npm-install@v1.6.0
22+
uses: bahmutov/npm-install@v1.7.10
2323
with:
2424
working-directory: 'beta'
2525

.github/workflows/beta_site_lint.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
name: Beta Site Lint / Heading ID check
22

33
on:
4+
push:
5+
branches:
6+
- main # change this if your default branch is named differently
47
pull_request:
58
types: [opened, synchronize, reopened]
69

@@ -18,7 +21,7 @@ jobs:
1821
node-version: 12.x
1922

2023
- name: Install deps and build (with cache)
21-
uses: bahmutov/npm-install@v1.6.0
24+
uses: bahmutov/npm-install@v1.7.10
2225
with:
2326
working-directory: 'beta'
2427

.github/workflows/nodejs.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
name: Build
1+
name: Lint / Flow check
22

33
on:
4+
push:
5+
branches:
6+
- main # change this if your default branch is named differently
47
pull_request:
58
types: [opened, synchronize, reopened]
69

@@ -18,7 +21,7 @@ jobs:
1821
node-version: 12.x
1922

2023
- name: Install deps and build (with cache)
21-
uses: bahmutov/npm-install@v1.6.0
24+
uses: bahmutov/npm-install@v1.7.10
2225

2326
- name: Lint codebase
2427
run: yarn ci-check

beta/.husky/pre-commit

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
. "$(dirname "$0")/_/husky.sh"
33

44
cd beta
5-
yarn lint-heading-ids
6-
yarn prettier
7-
yarn lint:fix
5+
yarn lint-staged

beta/.prettierrc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,19 @@
33
"singleQuote": true,
44
"bracketSameLine": true,
55
"trailingComma": "es5",
6-
"printWidth": 80
6+
"printWidth": 80,
7+
"overrides": [
8+
{
9+
"files": "*.css",
10+
"options": {
11+
"parser": "css"
12+
}
13+
},
14+
{
15+
"files": "*.md",
16+
"options": {
17+
"parser": "mdx"
18+
}
19+
}
20+
]
721
}

beta/package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"build": "next build && node ./scripts/generateRSS.js && node ./scripts/generateRedirects.js",
1010
"lint": "next lint",
1111
"lint:fix": "next lint --fix",
12-
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx}\"",
13-
"nit:source": "prettier --config .prettierrc --list-different \"{plugins,src}/**/*.{js,ts,jsx,tsx}\"",
12+
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx,css}\"",
13+
"nit:source": "prettier --config .prettierrc --list-different \"{plugins,src}/**/*.{js,ts,jsx,tsx,css}\"",
1414
"prettier": "yarn format:source",
1515
"prettier:diff": "yarn nit:source",
16-
"lint-heading-ids":"node scripts/headingIdLinter.js",
16+
"lint-heading-ids": "node scripts/headingIdLinter.js",
1717
"fix-headings": "node scripts/headingIdLinter.js --fix",
1818
"ci-check": "npm-run-all prettier:diff --parallel lint tsc lint-heading-ids",
1919
"tsc": "tsc --noEmit",
@@ -22,7 +22,7 @@
2222
"check-all": "npm-run-all prettier lint:fix tsc"
2323
},
2424
"dependencies": {
25-
"@codesandbox/sandpack-react": "0.13.6-experimental.0",
25+
"@codesandbox/sandpack-react": "0.13.9-experimental.6",
2626
"@docsearch/css": "3.0.0-alpha.41",
2727
"@docsearch/react": "3.0.0-alpha.41",
2828
"@headlessui/react": "^1.3.0",
@@ -32,7 +32,7 @@
3232
"date-fns": "^2.16.1",
3333
"debounce": "^1.2.1",
3434
"github-slugger": "^1.3.0",
35-
"next": "^12.0.5",
35+
"next": "^12.0.9",
3636
"parse-numeric-range": "^1.2.0",
3737
"react": "experimental",
3838
"react-collapsed": "3.1.0",
@@ -67,13 +67,14 @@
6767
"gray-matter": "^4.0.2",
6868
"husky": "^7.0.4",
6969
"is-ci": "^3.0.1",
70+
"lint-staged": ">=10",
7071
"mdast-util-to-string": "^1.1.0",
7172
"npm-run-all": "^4.1.5",
7273
"patch-package": "^6.2.2",
7374
"postcss": "^8.3.6",
7475
"postcss-flexbugs-fixes": "4.2.1",
7576
"postcss-preset-env": "^6.7.0",
76-
"prettier": "^2.1.1",
77+
"prettier": "^2.5.1",
7778
"reading-time": "^1.2.0",
7879
"remark": "^12.0.1",
7980
"remark-external-links": "^7.0.0",
@@ -96,5 +97,9 @@
9697
"budget": null,
9798
"budgetPercentIncreaseRed": 10,
9899
"showDetails": true
100+
},
101+
"lint-staged": {
102+
"*.{js,ts,jsx,tsx,css}": "yarn prettier",
103+
"*.md": "yarn fix-headings"
99104
}
100105
}

beta/patches/@next+plugin-google-analytics+9.5.2.patch

Lines changed: 0 additions & 35 deletions
This file was deleted.

beta/src/components/Layout/LayoutPost.tsx

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

5-
import {MDXProvider} from '@mdx-js/react';
5+
// @ts-ignore
6+
import {MDXContext} from '@mdx-js/react';
67
import recentPostsRouteTree from 'blogIndexRecent.json';
78
import {DocsPageFooter} from 'components/DocsFooter';
89
import {ExternalLink} from 'components/ExternalLink';
@@ -87,7 +88,9 @@ function LayoutPost({meta, children}: LayoutPostProps) {
8788
</span>
8889
</p>
8990

90-
<MDXProvider components={MDXComponents}>{children}</MDXProvider>
91+
<MDXContext.Provider value={MDXComponents}>
92+
{children}
93+
</MDXContext.Provider>
9194
<DocsPageFooter
9295
route={route}
9396
nextRoute={nextRoute}

beta/src/components/Layout/MarkdownPage.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
*/
44

55
import * as React from 'react';
6-
import {MDXProvider} from '@mdx-js/react';
6+
// @ts-ignore
7+
import {MDXContext} from '@mdx-js/react';
78
import {DocsPageFooter} from 'components/DocsFooter';
89
import {MDXComponents} from 'components/MDX/MDXComponents';
910
import {Seo} from 'components/Seo';
@@ -49,9 +50,9 @@ export function MarkdownPage<
4950
}
5051
if (child.props.mdxType === 'Recipes') {
5152
return {
52-
url: '#recipes',
53+
url: '#' + (child.props.titleId ?? 'examples'),
5354
depth: 0,
54-
text: 'Recipes',
55+
text: child.props.titleText ?? 'Examples',
5556
};
5657
}
5758
if (child.props.mdxType === 'Recap') {
@@ -135,9 +136,9 @@ export function MarkdownPage<
135136
)}
136137
<div className="px-5 sm:px-12">
137138
<div className="max-w-7xl mx-auto">
138-
<MDXProvider components={MDXComponents}>
139+
<MDXContext.Provider value={MDXComponents}>
139140
{finalChildren}
140-
</MDXProvider>
141+
</MDXContext.Provider>
141142
</div>
142143
<DocsPageFooter
143144
route={route}

beta/src/components/MDX/Challenges/Challenges.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import {IconArrowSmall} from '../../Icon/IconArrowSmall';
1414
interface ChallengesProps {
1515
children: React.ReactElement[];
1616
isRecipes?: boolean;
17+
titleText?: string;
18+
titleId?: string;
1719
}
1820

1921
export interface ChallengeContents {
@@ -66,7 +68,12 @@ const parseChallengeContents = (
6668
return contents;
6769
};
6870

69-
export function Challenges({children, isRecipes}: ChallengesProps) {
71+
export function Challenges({
72+
children,
73+
isRecipes,
74+
titleText = isRecipes ? 'Try out some examples' : 'Try out some challenges',
75+
titleId = isRecipes ? 'examples' : 'challenges',
76+
}: ChallengesProps) {
7077
const challenges = parseChallengeContents(children);
7178
const scrollAnchorRef = React.useRef<HTMLDivElement>(null);
7279

@@ -112,12 +119,12 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
112119
)}>
113120
<div ref={scrollAnchorRef} className="py-2 px-5 sm:px-8 pb-0 md:pb-0">
114121
<H2
115-
id={isRecipes ? 'recipes' : 'challenges'}
122+
id={titleId}
116123
className={cn(
117124
'text-3xl mb-2 leading-10 relative',
118125
isRecipes ? 'text-purple-50 dark:text-purple-30' : 'text-link'
119126
)}>
120-
{isRecipes ? 'Try out some recipes' : 'Try out some challenges'}
127+
{titleText}
121128
</H2>
122129
{challenges.length > 1 && (
123130
<Navigation
@@ -132,8 +139,8 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
132139
<div key={activeChallenge}>
133140
<h3 className="text-xl text-primary dark:text-primary-dark mb-2">
134141
<div className="font-bold block md:inline">
135-
{isRecipes ? 'Recipe' : 'Challenge'} {currentChallenge.order} of{' '}
136-
{challenges.length}
142+
{isRecipes ? 'Example' : 'Challenge'} {currentChallenge.order}{' '}
143+
of {challenges.length}
137144
<span className="text-primary dark:text-primary-dark">: </span>
138145
</div>
139146
{currentChallenge.name}
@@ -179,7 +186,7 @@ export function Challenges({children, isRecipes}: ChallengesProps) {
179186
setShowSolution(false);
180187
}}
181188
active>
182-
Next {isRecipes ? 'Recipe' : 'Challenge'}
189+
Next {isRecipes ? 'Example' : 'Challenge'}
183190
<IconArrowSmall
184191
displayDirection="right"
185192
className="block ml-1.5"

beta/src/components/MDX/MDXComponents.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,15 @@ function MathI({children}: {children: any}) {
135135
);
136136
}
137137

138-
function YouWillLearn({children}: {children: any}) {
139-
return <SimpleCallout title="You will learn">{children}</SimpleCallout>;
138+
function YouWillLearn({
139+
children,
140+
isChapter,
141+
}: {
142+
children: any;
143+
isChapter?: boolean;
144+
}) {
145+
let title = isChapter ? 'In this chapter' : 'You will learn';
146+
return <SimpleCallout title={title}>{children}</SimpleCallout>;
140147
}
141148

142149
// TODO: typing.

beta/src/components/MDX/Sandpack/DownloadButton.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ ${css}
7474
<button
7575
className="text-sm text-primary dark:text-primary-dark inline-flex items-center hover:text-link duration-100 ease-in transition mx-1"
7676
onClick={downloadHTML}
77-
title="Refresh Sandpack"
77+
title="Download Sandbox"
7878
type="button">
7979
<IconArrowSmall
8080
displayDirection="down"

beta/src/components/MDX/Sandpack/Preview.tsx

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function Preview({
4646
errorScreenRegisteredRef,
4747
openInCSBRegisteredRef,
4848
loadingScreenRegisteredRef,
49+
status,
4950
} = sandpack;
5051

5152
if (
@@ -67,30 +68,38 @@ export function Preview({
6768
errorScreenRegisteredRef.current = true;
6869
loadingScreenRegisteredRef.current = true;
6970

70-
React.useEffect(() => {
71+
React.useEffect(function createBundler() {
7172
const iframeElement = iframeRef.current!;
7273
registerBundler(iframeElement, clientId.current);
7374

74-
const unsub = listen((message: any) => {
75-
if (message.type === 'resize') {
76-
setComputedAutoHeight(message.height);
77-
} else if (message.type === 'start') {
78-
if (message.firstLoad) {
79-
setIsReady(false);
80-
}
81-
} else if (message.type === 'test') {
82-
// Does it make sense that we're listening to "test" event?
83-
// Not really. Does it cause less flicker than "done"? Yes.
84-
setIsReady(true);
85-
}
86-
}, clientId.current);
87-
8875
return () => {
89-
unsub();
9076
unregisterBundler(clientId.current);
9177
};
9278
}, []);
9379

80+
React.useEffect(
81+
function bundlerListener() {
82+
const unsubscribe = listen((message: any) => {
83+
if (message.type === 'resize') {
84+
setComputedAutoHeight(message.height);
85+
} else if (message.type === 'start') {
86+
if (message.firstLoad) {
87+
setIsReady(false);
88+
}
89+
} else if (message.type === 'done') {
90+
setIsReady(true);
91+
}
92+
}, clientId.current);
93+
94+
return () => {
95+
setIsReady(false);
96+
setComputedAutoHeight(null);
97+
unsubscribe();
98+
};
99+
},
100+
[status === 'idle']
101+
);
102+
94103
const viewportStyle = computeViewportSize('auto', 'portrait');
95104
const overrideStyle = error
96105
? {
@@ -175,7 +184,10 @@ export function Preview({
175184
<Error error={error} />
176185
</div>
177186
)}
178-
<LoadingOverlay clientId={clientId.current} />
187+
<LoadingOverlay
188+
clientId={clientId.current}
189+
loading={!isReady && iframeComputedHeight === null}
190+
/>
179191
</div>
180192
</div>
181193
);

beta/src/components/MDX/Sandpack/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ function Sandpack(props: SandpackProps) {
127127
<SandpackProvider
128128
template="react"
129129
customSetup={{...setup, files: files}}
130-
autorun={autorun}>
130+
autorun={autorun}
131+
initMode="user-visible"
132+
initModeObserverOptions={{rootMargin: '1400px 0px'}}>
131133
<CustomPreset
132134
isSingleFile={isSingleFile}
133135
showDevTools={showDevTools}

0 commit comments

Comments
 (0)