Skip to content

Commit 1459076

Browse files
authored
Merge pull request #313 from reactjs/sync-6d965422
Sync with reactjs.org @ 6d96542
2 parents 45c988c + 8947f96 commit 1459076

Some content is hidden

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

53 files changed

+925
-553
lines changed

.nvmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
12.16.1
1+
12.22.0

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repo contains the source code and documentation powering [reactjs.org](http
88

99
1. Git
1010
1. Node: any 12.x version starting with v12.0.0 or greater
11-
1. Yarn: See [Yarn website for installation instructions](https://yarnpkg.com/lang/en/docs/install/)
11+
1. Yarn v1: See [Yarn website for installation instructions](https://yarnpkg.com/lang/en/docs/install/)
1212
1. A fork of the repo (for any contributions)
1313
1. A clone of the [reactjs.org repo](https://github.com/reactjs/reactjs.org) on your local machine
1414

beta/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,8 @@ yarn-error.log*
3333

3434
# vercel
3535
.vercel
36+
37+
# external fonts
38+
public/fonts/Optimistic_Display_W_Lt.woff2
39+
public/fonts/Optimistic_Display_W_Md.woff2
40+
public/fonts/Optimistic_Display_W_Bd.woff2

beta/next.config.js

+39-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,30 @@ const path = require('path');
66
const {remarkPlugins} = require('./plugins/markdownToHtml');
77
const redirects = require('./src/redirects.json');
88

9-
module.exports = {
9+
/**
10+
* @type {import('next').NextConfig}
11+
**/
12+
const nextConfig = {
1013
pageExtensions: ['jsx', 'js', 'ts', 'tsx', 'mdx', 'md'],
1114
experimental: {
1215
plugins: true,
13-
// TODO: this doesn't work because https://github.com/vercel/next.js/issues/30714
14-
concurrentFeatures: false,
1516
scrollRestoration: true,
17+
legacyBrowsers: false,
18+
browsersListForSwc: true,
1619
},
1720
async redirects() {
1821
return redirects.redirects;
1922
},
20-
rewrites() {
21-
return [
22-
{
23-
source: '/feed.xml',
24-
destination: '/_next/static/feed.xml',
25-
},
26-
];
27-
},
23+
// TODO: this causes extra router.replace() on every page.
24+
// Let's disable until we figure out what's going on.
25+
// rewrites() {
26+
// return [
27+
// {
28+
// source: '/feed.xml',
29+
// destination: '/_next/static/feed.xml',
30+
// },
31+
// ];
32+
// },
2833
webpack: (config, {dev, isServer, ...options}) => {
2934
if (process.env.ANALYZE) {
3035
const {BundleAnalyzerPlugin} = require('webpack-bundle-analyzer');
@@ -38,6 +43,27 @@ module.exports = {
3843
);
3944
}
4045

46+
// Don't bundle the shim unnecessarily.
47+
config.resolve.alias['use-sync-external-store/shim'] = 'react';
48+
49+
const {IgnorePlugin} = require('webpack');
50+
config.plugins.push(
51+
new IgnorePlugin({
52+
checkResource(resource, context) {
53+
if (
54+
/\/eslint\/lib\/rules$/.test(context) &&
55+
/\.\/[\w-]+(\.js)?$/.test(resource)
56+
) {
57+
// Skips imports of built-in rules that ESLint
58+
// tries to carry into the bundle by default.
59+
// We only want the engine and the React rules.
60+
return true;
61+
}
62+
return false;
63+
},
64+
})
65+
);
66+
4167
// Add our custom markdown loader in order to support frontmatter
4268
// and layout
4369
config.module.rules.push({
@@ -57,3 +83,5 @@ module.exports = {
5783
return config;
5884
},
5985
};
86+
87+
module.exports = nextConfig;

beta/package.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"scripts": {
77
"analyze": "ANALYZE=true next build",
88
"dev": "next",
9-
"build": "next build && node ./scripts/generateRSS.js && node ./scripts/generateRedirects.js",
9+
"build": "next build && node ./scripts/generateRSS.js && node ./scripts/generateRedirects.js && node ./scripts/downloadFonts.js",
1010
"lint": "next lint",
1111
"lint:fix": "next lint --fix",
1212
"format:source": "prettier --config .prettierrc --write \"{plugins,src}/**/*.{js,ts,jsx,tsx,css}\"",
@@ -22,7 +22,7 @@
2222
"check-all": "npm-run-all prettier lint:fix tsc"
2323
},
2424
"dependencies": {
25-
"@codesandbox/sandpack-react": "v0.14.3-experimental.1",
25+
"@codesandbox/sandpack-react": "v0.19.8-experimental.4",
2626
"@docsearch/css": "3.0.0-alpha.41",
2727
"@docsearch/react": "3.0.0-alpha.41",
2828
"@headlessui/react": "^1.3.0",
@@ -33,23 +33,24 @@
3333
"debounce": "^1.2.1",
3434
"ga-lite": "^2.1.4",
3535
"github-slugger": "^1.3.0",
36-
"next": "^12.0.10",
36+
"next": "12.1.7-canary.11",
3737
"parse-numeric-range": "^1.2.0",
38-
"react": "experimental",
38+
"react": "0.0.0-experimental-82c64e1a4-20220520",
3939
"react-collapsed": "3.1.0",
40-
"react-dom": "experimental",
40+
"react-dom": "0.0.0-experimental-82c64e1a4-20220520",
4141
"scroll-into-view-if-needed": "^2.2.25"
4242
},
4343
"devDependencies": {
4444
"@mdx-js/loader": "^1.6.16",
4545
"@types/body-scroll-lock": "^2.6.1",
4646
"@types/classnames": "^2.2.10",
47+
"@types/debounce": "^1.2.1",
4748
"@types/github-slugger": "^1.3.0",
4849
"@types/mdx-js__react": "^1.5.2",
4950
"@types/node": "^14.6.4",
5051
"@types/parse-numeric-range": "^0.0.1",
51-
"@types/react": "^16.9.46",
52-
"@types/react-dom": "^16.9.8",
52+
"@types/react": "^18.0.9",
53+
"@types/react-dom": "^18.0.5",
5354
"@typescript-eslint/eslint-plugin": "2.x",
5455
"@typescript-eslint/parser": "2.x",
5556
"asyncro": "^3.0.0",

beta/patches/@codesandbox+sandpack-react+0.14.3-experimental.1.patch renamed to beta/patches/@codesandbox+sandpack-react+0.19.8-experimental.4.patch

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/@codesandbox/sandpack-react/dist/esm/index.js b/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
2-
index 4acfc3a..d00e57d 100644
2+
index ced9bd3..7e5e366 100644
33
--- a/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
44
+++ b/node_modules/@codesandbox/sandpack-react/dist/esm/index.js
55
@@ -566,17 +566,16 @@ var REACT_TEMPLATE = {

beta/scripts/downloadFonts.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*/
4+
5+
const {execSync} = require('child_process');
6+
7+
// So that we don't need to check them into the repo.
8+
// Serving them from the same domain is better for perf so do this on deploy.
9+
execSync(
10+
'curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Lt.woff2 --output public/fonts/Optimistic_Display_W_Lt.woff2'
11+
);
12+
execSync(
13+
'curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Md.woff2 --output public/fonts/Optimistic_Display_W_Md.woff2'
14+
);
15+
execSync(
16+
'curl https://conf.reactjs.org/fonts/Optimistic_Display_W_Bd.woff2 --output public/fonts/Optimistic_Display_W_Bd.woff2'
17+
);

beta/src/components/Layout/Feedback.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
import * as React from 'react';
66
import {useRouter} from 'next/router';
7-
// @ts-ignore
8-
import galite from 'ga-lite';
7+
import {ga} from '../../utils/analytics';
98

109
export function Feedback({onSubmit = () => {}}: {onSubmit?: () => void}) {
1110
const {pathname} = useRouter();
@@ -48,7 +47,7 @@ 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-
galite(
50+
ga(
5251
'send',
5352
'event',
5453
'button',

beta/src/components/Layout/Nav/MobileNav.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export function MobileNav() {
5757
API
5858
</TabButton>
5959
</div>
60-
<SidebarRouteTree routeTree={tree as RouteItem} isMobile={true} />
60+
{/* No fallback UI so need to be careful not to suspend directly inside. */}
61+
<React.Suspense fallback={null}>
62+
<SidebarRouteTree routeTree={tree as RouteItem} isMobile={true} />
63+
</React.Suspense>
6164
</>
6265
);
6366
}

beta/src/components/Layout/Page.tsx

+10-7
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,17 @@ export function Page({routeTree, children}: PageProps) {
2626
<Sidebar />
2727
</div>
2828

29-
<div className="flex flex-1 w-full h-full self-stretch">
30-
<div className="w-full min-w-0">
31-
<main className="flex flex-1 self-stretch mt-16 sm:mt-10 flex-col items-end justify-around">
32-
{children}
33-
<Footer />
34-
</main>
29+
{/* No fallback UI so need to be careful not to suspend directly inside. */}
30+
<React.Suspense fallback={null}>
31+
<div className="flex flex-1 w-full h-full self-stretch">
32+
<div className="w-full min-w-0">
33+
<main className="flex flex-1 self-stretch mt-16 sm:mt-10 flex-col items-end justify-around">
34+
{children}
35+
<Footer />
36+
</main>
37+
</div>
3538
</div>
36-
</div>
39+
</React.Suspense>
3740
</div>
3841
</SidebarContext.Provider>
3942
</MenuProvider>

beta/src/components/Layout/Sidebar/Sidebar.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ export function Sidebar() {
4242
{isMobileSidebar ? (
4343
<MobileNav />
4444
) : (
45-
<SidebarRouteTree routeTree={routeTree} />
45+
/* No fallback UI so need to be careful not to suspend directly inside. */
46+
<React.Suspense fallback={null}>
47+
<SidebarRouteTree routeTree={routeTree} />
48+
</React.Suspense>
4649
)}
4750
</nav>
4851
<div className="sticky bottom-0 hidden lg:block">

beta/src/components/Layout/Sidebar/SidebarLink.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ interface SidebarLinkProps {
2121
isExpanded?: boolean;
2222
isBreadcrumb?: boolean;
2323
hideArrow?: boolean;
24+
isPending: boolean;
2425
}
2526

2627
export function SidebarLink({
@@ -32,6 +33,7 @@ export function SidebarLink({
3233
isExpanded,
3334
isBreadcrumb,
3435
hideArrow,
36+
isPending,
3537
}: SidebarLinkProps) {
3638
const ref = React.useRef<HTMLAnchorElement>(null);
3739
const isMobile = useIsMobile();
@@ -67,8 +69,11 @@ export function SidebarLink({
6769
!selected && !heading,
6870
'text-base text-link dark:text-link-dark bg-highlight dark:bg-highlight-dark border-blue-40 hover:bg-highlight hover:text-link dark:hover:bg-highlight-dark dark:hover:text-link-dark':
6971
selected,
72+
'dark:bg-gray-60 bg-gray-3 dark:hover:bg-gray-60 hover:bg-gray-3':
73+
isPending,
7074
}
7175
)}>
76+
{/* This here needs to be refactored ofc */}
7277
{title}
7378
{isExpanded != null && !heading && !hideArrow && (
7479
<span

beta/src/components/Layout/Sidebar/SidebarRouteTree.tsx

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {useRouteMeta} from '../useRouteMeta';
1111
import {SidebarLink} from './SidebarLink';
1212
import useCollapse from 'react-collapsed';
1313
import {useLayoutEffect} from 'react';
14+
import usePendingRoute from 'hooks/usePendingRoute';
1415

1516
interface SidebarRouteTreeProps {
1617
isMobile?: boolean;
@@ -77,8 +78,9 @@ export function SidebarRouteTree({
7778
}: SidebarRouteTreeProps) {
7879
const {breadcrumbs} = useRouteMeta(routeTree);
7980
const {pathname} = useRouter();
80-
const slug = pathname;
81+
const pendingRoute = usePendingRoute();
8182

83+
const slug = pathname;
8284
const currentRoutes = routeTree.routes as RouteItem[];
8385
const expandedPath = currentRoutes.reduce(
8486
(acc: string | undefined, curr: RouteItem) => {
@@ -121,6 +123,7 @@ export function SidebarRouteTree({
121123
<SidebarLink
122124
key={`${title}-${path}-${level}-link`}
123125
href={pagePath}
126+
isPending={pendingRoute === pagePath}
124127
selected={selected}
125128
level={level}
126129
title={title}
@@ -143,6 +146,7 @@ export function SidebarRouteTree({
143146
return (
144147
<li key={`${title}-${path}-${level}-link`}>
145148
<SidebarLink
149+
isPending={pendingRoute === pagePath}
146150
href={pagePath}
147151
selected={selected}
148152
level={level}

beta/src/components/Layout/Toc.tsx

+1-12
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

+1-1
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

+1-1
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/Challenges/Navigation.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React, {createRef} from 'react';
66
import cn from 'classnames';
77
import {IconChevron} from 'components/Icon/IconChevron';
88
import {ChallengeContents} from './Challenges';
9-
const debounce = require('debounce');
9+
import {debounce} from 'debounce';
1010

1111
export function Navigation({
1212
challenges,
@@ -122,7 +122,7 @@ export function Navigation({
122122
onClick={handleScrollRight}
123123
aria-label="Scroll right"
124124
className={cn(
125-
'bg-secondary-button dark:bg-secondary-button-dark h-8 px-2 rounded-r-lg',
125+
'bg-secondary-button dark:bg-secondary-button-dark h-8 px-2 rounded-r',
126126
{
127127
'text-primary dark:text-primary-dark': canScrollRight,
128128
'text-gray-30': !canScrollRight,

0 commit comments

Comments
 (0)