Skip to content

Commit aaa0517

Browse files
committed
Merge branch 'main' of https://github.com/reactjs/reactjs.org into sync-ee754727
2 parents f243128 + ee75472 commit aaa0517

File tree

16 files changed

+170
-192
lines changed

16 files changed

+170
-192
lines changed

beta/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
"@types/mdx-js__react": "^1.5.2",
4949
"@types/node": "^14.6.4",
5050
"@types/parse-numeric-range": "^0.0.1",
51-
"@types/react": "^16.9.46",
52-
"@types/react-dom": "^16.9.8",
51+
"@types/react": "^18.0.9",
52+
"@types/react-dom": "^18.0.5",
5353
"@typescript-eslint/eslint-plugin": "2.x",
5454
"@typescript-eslint/parser": "2.x",
5555
"asyncro": "^3.0.0",

beta/src/components/Layout/Toc.tsx

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export function Toc({
2828
<h2 className="mb-3 lg:mb-3 uppercase tracking-wide font-bold text-sm text-secondary dark:text-secondary-dark px-4 w-full">
2929
On this page
3030
</h2>
31-
<div className="toc h-full overflow-y-auto pl-4">
31+
<div className="h-full overflow-y-auto pl-4 max-h-[calc(100vh-7.5rem)]">
3232
<ul className="space-y-2 pb-16">
3333
{headings &&
3434
headings.length > 0 &&
@@ -65,17 +65,6 @@ export function Toc({
6565
})}
6666
</ul>
6767
</div>
68-
<style jsx global>{`
69-
.toc {
70-
/** Screen - nav - toc offset */
71-
max-height: calc(100vh - 7.5rem);
72-
}
73-
.toc-link > code {
74-
overflow-wrap: break-word;
75-
white-space: pre-wrap;
76-
font-size: 90%;
77-
}
78-
`}</style>
7968
</nav>
8069
);
8170
}

beta/src/components/Layout/useMediaQuery.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {useState, useCallback, useEffect} from 'react';
77
const useMediaQuery = (width: number) => {
88
const [targetReached, setTargetReached] = useState(false);
99

10-
const updateTarget = useCallback((e) => {
10+
const updateTarget = useCallback((e: MediaQueryListEvent) => {
1111
if (e.matches) {
1212
setTargetReached(true);
1313
} else {

beta/src/components/Layout/useTocHighlight.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const TOP_OFFSET = 75;
99

1010
export function getHeaderAnchors(): HTMLAnchorElement[] {
1111
return Array.prototype.filter.call(
12-
document.getElementsByClassName(siteConfig.headerIdConfig.className),
12+
document.getElementsByClassName('mdx-header-anchor'),
1313
function (testElement) {
1414
return (
1515
testElement.parentNode.nodeName === 'H1' ||

beta/src/components/MDX/Heading.tsx

Lines changed: 25 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ export interface HeadingProps {
1414
as?: any;
1515
}
1616

17-
const anchorClassName = siteConfig.headerIdConfig.className;
18-
1917
const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading(
2018
{as: Comp = 'div', className, children, id, isPageAnchor = true, ...props},
2119
ref
@@ -26,71 +24,31 @@ const Heading = forwardRefWithAs<HeadingProps, 'div'>(function Heading(
2624
}
2725

2826
return (
29-
<>
30-
<Comp id={id} {...props} ref={ref} className={cn('heading', className)}>
31-
{children}
32-
{isPageAnchor && (
33-
<a
34-
href={`#${id}`}
35-
aria-label={label}
36-
title={label}
37-
className={cn(
38-
anchorClassName,
39-
Comp === 'h1' ? 'hidden' : 'inline-block'
40-
)}>
41-
<svg
42-
width="1em"
43-
height="1em"
44-
viewBox="0 0 13 13"
45-
xmlns="http://www.w3.org/2000/svg"
46-
className="text-gray-70 ml-2 h-5 w-5">
47-
<g fill="currentColor" fillRule="evenodd">
48-
<path d="M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z" />
49-
<path d="M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z" />
50-
</g>
51-
</svg>
52-
</a>
53-
)}
54-
</Comp>
55-
<style jsx>
56-
{`
57-
.heading {
58-
scroll-margin-top: 2.5em;
59-
/* Space for the anchor */
60-
padding-right: 1em;
61-
}
62-
.heading:before {
63-
height: 6rem;
64-
margin-top: -6rem;
65-
visibility: hidden;
66-
content: '';
67-
}
68-
69-
.heading .${anchorClassName} {
70-
/* Prevent the anchor from
71-
overflowing to its own line */
72-
height: 0px;
73-
width: 0px;
74-
}
75-
76-
.heading .${anchorClassName} svg {
77-
display: inline;
78-
}
79-
80-
.heading .${anchorClassName} svg {
81-
visibility: hidden;
82-
}
83-
84-
.heading:hover .${anchorClassName} svg {
85-
visibility: visible;
86-
}
87-
88-
.heading .${anchorClassName}:focus svg {
89-
visibility: visible;
90-
}
91-
`}
92-
</style>
93-
</>
27+
<Comp id={id} {...props} ref={ref} className={cn('mdx-heading', className)}>
28+
{children}
29+
{isPageAnchor && (
30+
<a
31+
href={`#${id}`}
32+
aria-label={label}
33+
title={label}
34+
className={cn(
35+
'mdx-header-anchor',
36+
Comp === 'h1' ? 'hidden' : 'inline-block'
37+
)}>
38+
<svg
39+
width="1em"
40+
height="1em"
41+
viewBox="0 0 13 13"
42+
xmlns="http://www.w3.org/2000/svg"
43+
className="text-gray-70 ml-2 h-5 w-5">
44+
<g fill="currentColor" fillRule="evenodd">
45+
<path d="M7.778 7.975a2.5 2.5 0 0 0 .347-3.837L6.017 2.03a2.498 2.498 0 0 0-3.542-.007 2.5 2.5 0 0 0 .006 3.543l1.153 1.15c.07-.29.154-.563.25-.773.036-.077.084-.16.14-.25L3.18 4.85a1.496 1.496 0 0 1 .002-2.12 1.496 1.496 0 0 1 2.12 0l2.124 2.123a1.496 1.496 0 0 1-.333 2.37c.16.246.42.504.685.752z" />
46+
<path d="M5.657 4.557a2.5 2.5 0 0 0-.347 3.837l2.108 2.108a2.498 2.498 0 0 0 3.542.007 2.5 2.5 0 0 0-.006-3.543L9.802 5.815c-.07.29-.154.565-.25.774-.036.076-.084.16-.14.25l.842.84c.585.587.59 1.532 0 2.122-.587.585-1.532.59-2.12 0L6.008 7.68a1.496 1.496 0 0 1 .332-2.372c-.16-.245-.42-.503-.685-.75z" />
47+
</g>
48+
</svg>
49+
</a>
50+
)}
51+
</Comp>
9452
);
9553
});
9654

beta/src/components/MDX/MDXComponents.tsx

Lines changed: 5 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -80,21 +80,11 @@ const Blockquote = ({
8080
...props
8181
}: JSX.IntrinsicElements['blockquote']) => {
8282
return (
83-
<>
84-
<blockquote
85-
className="mdx-blockquote py-4 px-8 my-8 shadow-inner bg-highlight dark:bg-highlight-dark bg-opacity-50 rounded-lg leading-6 flex relative"
86-
{...props}>
87-
<span className="block relative">{children}</span>
88-
</blockquote>
89-
<style jsx global>{`
90-
.mdx-blockquote > span > p:first-of-type {
91-
margin-bottom: 0;
92-
}
93-
.mdx-blockquote > span > p:last-of-type {
94-
margin-bottom: 1rem;
95-
}
96-
`}</style>
97-
</>
83+
<blockquote
84+
className="mdx-blockquote py-4 px-8 my-8 shadow-inner bg-highlight dark:bg-highlight-dark bg-opacity-50 rounded-lg leading-6 flex relative"
85+
{...props}>
86+
<span className="block relative">{children}</span>
87+
</blockquote>
9888
);
9989
};
10090

@@ -274,72 +264,6 @@ function IllustrationBlock({
274264
<div className="mdx-illustration-block">{images}</div>
275265
)}
276266
{author ? <AuthorCredit author={author} authorLink={authorLink} /> : null}
277-
<style jsx global>{`
278-
.mdx-illustration-block {
279-
display: flex;
280-
flex-direction: row;
281-
flex-wrap: nowrap;
282-
justify-content: center;
283-
align-content: stretch;
284-
align-items: stretch;
285-
gap: 42px;
286-
}
287-
ol.mdx-illustration-block {
288-
gap: 60px;
289-
}
290-
.mdx-illustration-block li {
291-
display: flex;
292-
align-items: flex-start;
293-
align-content: stretch;
294-
justify-content: space-around;
295-
position: relative;
296-
padding: 1rem;
297-
}
298-
.mdx-illustration-block figure {
299-
display: flex;
300-
flex-direction: column;
301-
align-content: center;
302-
align-items: center;
303-
304-
justify-content: space-between;
305-
position: relative;
306-
height: 100%;
307-
}
308-
.mdx-illustration-block li:after {
309-
content: ' ';
310-
display: block;
311-
position: absolute;
312-
top: 50%;
313-
right: 100%;
314-
transform: translateY(-50%);
315-
width: 60px;
316-
height: 49px;
317-
background: center / contain no-repeat url('/images/g_arrow.png');
318-
}
319-
.mdx-illustration-block li:first-child:after {
320-
content: ' ';
321-
display: none;
322-
}
323-
.mdx-illustration-block img {
324-
max-height: 250px;
325-
width: 100%;
326-
}
327-
@media (max-width: 680px) {
328-
.mdx-illustration-block {
329-
flex-direction: column;
330-
}
331-
.mdx-illustration-block img {
332-
max-height: 200px;
333-
width: auto;
334-
}
335-
.mdx-illustration-block li:after {
336-
top: 0;
337-
left: 50%;
338-
right: auto;
339-
transform: translateX(-50%) translateY(-100%) rotate(90deg);
340-
}
341-
}
342-
`}</style>
343267
</div>
344268
);
345269
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ let supportsImportMap: boolean | void;
1212
function useSupportsImportMap() {
1313
function subscribe() {
1414
// It never updates.
15+
return () => {};
1516
}
1617
function getCurrentValue() {
1718
if (supportsImportMap === undefined) {
@@ -24,7 +25,7 @@ function useSupportsImportMap() {
2425
function getServerSnapshot() {
2526
return false;
2627
}
27-
// @ts-ignore
28+
2829
return React.useSyncExternalStore(
2930
subscribe,
3031
getCurrentValue,

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,23 @@ export function Preview({
6161
rawError = null;
6262
}
6363

64-
if (lintErrors.length > 0) {
65-
if (rawError == null || rawError.title === 'Runtime Exception') {
66-
// When there's a lint error, show it -- even over a runtime error.
67-
// (However, when there's a build error, we keep showing the build one.)
64+
// Memoized because it's fed to debouncing.
65+
const firstLintError = React.useMemo(() => {
66+
if (lintErrors.length === 0) {
67+
return null;
68+
} else {
6869
const {line, column, message} = lintErrors[0];
69-
rawError = {
70+
return {
7071
title: 'Lint Error',
7172
message: `${line}:${column} - ${message}`,
7273
};
7374
}
75+
}, [lintErrors]);
76+
77+
if (rawError == null || rawError.title === 'Runtime Exception') {
78+
if (firstLintError !== null) {
79+
rawError = firstLintError;
80+
}
7481
}
7582

7683
// It changes too fast, causing flicker.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {createFileMap} from './createFileMap';
1111
import type {SandpackSetup} from '@codesandbox/sandpack-react';
1212

1313
type SandpackProps = {
14-
children: React.ReactChildren;
14+
children: React.ReactNode;
1515
autorun?: boolean;
1616
setup?: SandpackSetup;
1717
showDevTools?: boolean;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
*/
44

55
import * as React from 'react';
6-
import dynamic from 'next/dynamic';
76
import {createFileMap} from './createFileMap';
87

9-
const SandpackRoot = dynamic(() => import('./SandpackRoot'), {suspense: true});
8+
const SandpackRoot = React.lazy(() => import('./SandpackRoot'));
109

1110
const SandpackGlimmer = ({code}: {code: string}) => (
1211
<div className="sandpack-container my-8">

0 commit comments

Comments
 (0)