Skip to content

Commit 187e5aa

Browse files
authored
feat: React 18 + automatic JSX runtime + build --dev (#8961)
1 parent 76f9203 commit 187e5aa

File tree

69 files changed

+404
-209
lines changed

Some content is hidden

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

69 files changed

+404
-209
lines changed

.eslintrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ module.exports = {
6666
'@docusaurus',
6767
],
6868
rules: {
69+
'react/jsx-uses-react': OFF, // JSX runtime: automatic
70+
'react/react-in-jsx-scope': OFF, // JSX runtime: automatic
6971
'array-callback-return': WARNING,
7072
camelcase: WARNING,
7173
'class-methods-use-this': OFF, // It's a way of allowing private variables.
@@ -259,6 +261,9 @@ module.exports = {
259261
},
260262
{pattern: '@jest/globals', group: 'builtin', position: 'before'},
261263
{pattern: 'react', group: 'builtin', position: 'before'},
264+
{pattern: 'react-dom', group: 'builtin', position: 'before'},
265+
{pattern: 'react-dom/**', group: 'builtin', position: 'before'},
266+
{pattern: 'stream', group: 'builtin', position: 'before'},
262267
{pattern: 'fs-extra', group: 'builtin'},
263268
{pattern: 'lodash', group: 'external', position: 'before'},
264269
{pattern: 'clsx', group: 'external', position: 'before'},

jest.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const ignorePatterns = [
3232
export default {
3333
rootDir: fileURLToPath(new URL('.', import.meta.url)),
3434
verbose: true,
35+
setupFiles: ['./jest/setup.js'],
3536
testEnvironmentOptions: {
3637
url: 'https://docusaurus.io/',
3738
},

jest/setup.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
import {TextEncoder} from 'util';
8+
9+
// Required for RTL renderHook SSR tests with React-18
10+
// See also https://github.com/testing-library/react-testing-library/issues/1120#issuecomment-1516132279
11+
global.TextEncoder = TextEncoder;

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
"lint-staged": "^13.1.2",
106106
"npm-run-all": "^4.1.5",
107107
"prettier": "^2.8.4",
108-
"react": "^17.0.2",
109-
"react-dom": "^17.0.2",
108+
"react": "^18.0.0",
109+
"react-dom": "^18.0.0",
110110
"react-helmet-async": "^1.3.0",
111-
"react-test-renderer": "^17.0.2",
111+
"react-test-renderer": "^18.0.0",
112112
"remark-parse": "^8.0.2",
113113
"rimraf": "^3.0.2",
114114
"sharp": "^0.31.3",

packages/create-docusaurus/templates/classic-typescript/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
"dependencies": {
1818
"@docusaurus/core": "^3.0.0-alpha.0",
1919
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
20-
"@mdx-js/react": "^2.1.5",
20+
"@mdx-js/react": "^2.3.0",
2121
"clsx": "^1.2.1",
2222
"prism-react-renderer": "^1.3.5",
23-
"react": "^17.0.2",
24-
"react-dom": "^17.0.2"
23+
"react": "^18.0.0",
24+
"react-dom": "^18.0.0"
2525
},
2626
"devDependencies": {
2727
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0",

packages/create-docusaurus/templates/classic/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"dependencies": {
1717
"@docusaurus/core": "^3.0.0-alpha.0",
1818
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
19-
"@mdx-js/react": "^2.1.5",
19+
"@mdx-js/react": "^2.3.0",
2020
"clsx": "^1.2.1",
2121
"prism-react-renderer": "^1.3.5",
22-
"react": "^17.0.2",
23-
"react-dom": "^17.0.2"
22+
"react": "^18.0.0",
23+
"react-dom": "^18.0.0"
2424
},
2525
"devDependencies": {
2626
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0"

packages/docusaurus-mdx-loader/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@
5959
"unist-util-remove-position": "^3.0.0"
6060
},
6161
"peerDependencies": {
62-
"react": "^16.8.4 || ^17.0.0",
63-
"react-dom": "^16.8.4 || ^17.0.0"
62+
"react": "^18.0.0",
63+
"react-dom": "^18.0.0"
6464
},
6565
"engines": {
6666
"node": ">=16.14"

packages/docusaurus-module-type-aliases/src/index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,12 @@ declare module '@docusaurus/router' {
242242
export {useHistory, useLocation, Redirect, matchPath} from 'react-router-dom';
243243
}
244244

245+
declare module '@docusaurus/useIsomorphicLayoutEffect' {
246+
import {useLayoutEffect} from 'react';
247+
248+
export = useLayoutEffect;
249+
}
250+
245251
declare module '@docusaurus/useDocusaurusContext' {
246252
import type {DocusaurusContext} from '@docusaurus/types';
247253

packages/docusaurus-plugin-client-redirects/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
"@docusaurus/types": "^3.0.0-alpha.0"
3333
},
3434
"peerDependencies": {
35-
"react": "^16.8.4 || ^17.0.0",
36-
"react-dom": "^16.8.4 || ^17.0.0"
35+
"react": "^18.0.0",
36+
"react-dom": "^18.0.0"
3737
},
3838
"engines": {
3939
"node": ">=16.14"

packages/docusaurus-plugin-content-blog/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636
"webpack": "^5.76.0"
3737
},
3838
"peerDependencies": {
39-
"react": "^16.8.4 || ^17.0.0",
40-
"react-dom": "^16.8.4 || ^17.0.0"
39+
"react": "^18.0.0",
40+
"react-dom": "^18.0.0"
4141
},
4242
"engines": {
4343
"node": ">=16.14"

packages/docusaurus-plugin-content-docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
"shelljs": "^0.8.5"
6161
},
6262
"peerDependencies": {
63-
"react": "^16.8.4 || ^17.0.0",
64-
"react-dom": "^16.8.4 || ^17.0.0"
63+
"react": "^18.0.0",
64+
"react-dom": "^18.0.0"
6565
},
6666
"engines": {
6767
"node": ">=16.14"

packages/docusaurus-plugin-content-pages/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"webpack": "^5.76.0"
2929
},
3030
"peerDependencies": {
31-
"react": "^16.8.4 || ^17.0.0",
32-
"react-dom": "^16.8.4 || ^17.0.0"
31+
"react": "^18.0.0",
32+
"react-dom": "^18.0.0"
3333
},
3434
"engines": {
3535
"node": ">=16.14"

packages/docusaurus-plugin-debug/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"tslib": "^2.5.0"
2929
},
3030
"peerDependencies": {
31-
"react": "^16.8.4 || ^17.0.0",
32-
"react-dom": "^16.8.4 || ^17.0.0"
31+
"react": "^18.0.0",
32+
"react-dom": "^18.0.0"
3333
},
3434
"engines": {
3535
"node": ">=16.14"

packages/docusaurus-plugin-google-analytics/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"tslib": "^2.5.0"
2525
},
2626
"peerDependencies": {
27-
"react": "^16.8.4 || ^17.0.0",
28-
"react-dom": "^16.8.4 || ^17.0.0"
27+
"react": "^18.0.0",
28+
"react-dom": "^18.0.0"
2929
},
3030
"engines": {
3131
"node": ">=16.14"

packages/docusaurus-plugin-google-gtag/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
"tslib": "^2.5.0"
2626
},
2727
"peerDependencies": {
28-
"react": "^16.8.4 || ^17.0.0",
29-
"react-dom": "^16.8.4 || ^17.0.0"
28+
"react": "^18.0.0",
29+
"react-dom": "^18.0.0"
3030
},
3131
"engines": {
3232
"node": ">=16.14"

packages/docusaurus-plugin-google-tag-manager/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
"tslib": "^2.5.0"
2525
},
2626
"peerDependencies": {
27-
"react": "^16.8.4 || ^17.0.0",
28-
"react-dom": "^16.8.4 || ^17.0.0"
27+
"react": "^18.0.0",
28+
"react-dom": "^18.0.0"
2929
},
3030
"engines": {
3131
"node": ">=16.14"

packages/docusaurus-plugin-ideal-image/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@docusaurus/theme-translations": "^3.0.0-alpha.0",
2727
"@docusaurus/types": "^3.0.0-alpha.0",
2828
"@docusaurus/utils-validation": "^3.0.0-alpha.0",
29-
"@endiliey/react-ideal-image": "^0.0.11",
29+
"@slorber/react-ideal-image": "^0.0.12",
3030
"react-waypoint": "^10.3.0",
3131
"sharp": "^0.31.3",
3232
"tslib": "^2.5.0",
@@ -38,8 +38,8 @@
3838
},
3939
"peerDependencies": {
4040
"jimp": "*",
41-
"react": "^16.8.4 || ^17.0.0",
42-
"react-dom": "^16.8.4 || ^17.0.0"
41+
"react": "^18.0.0",
42+
"react-dom": "^18.0.0"
4343
},
4444
"peerDependenciesMeta": {
4545
"jimp": {

packages/docusaurus-plugin-ideal-image/src/deps.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Note: the original type definition is WRONG. getIcon & getMessage receive
1313
* full state object.
1414
*/
15-
declare module '@endiliey/react-ideal-image' {
15+
declare module '@slorber/react-ideal-image' {
1616
import type {ComponentProps, ComponentType, CSSProperties} from 'react';
1717

1818
export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';

packages/docusaurus-plugin-ideal-image/src/theme/IdealImage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React from 'react';
99
import ReactIdealImage, {
1010
type IconKey,
1111
type State,
12-
} from '@endiliey/react-ideal-image';
12+
} from '@slorber/react-ideal-image';
1313
import {translate} from '@docusaurus/Translate';
1414

1515
import type {Props} from '@theme/IdealImage';

packages/docusaurus-plugin-pwa/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
"fs-extra": "^11.1.0"
4646
},
4747
"peerDependencies": {
48-
"react": "^16.8.4 || ^17.0.0",
49-
"react-dom": "^16.8.4 || ^17.0.0"
48+
"react": "^18.0.0",
49+
"react-dom": "^18.0.0"
5050
},
5151
"engines": {
5252
"node": ">=16.14"

packages/docusaurus-plugin-pwa/src/registerSw.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,14 @@ async function getIsAppInstalledRelatedApps() {
7272
if (!('getInstalledRelatedApps' in window.navigator)) {
7373
return false;
7474
}
75-
const relatedApps = await navigator.getInstalledRelatedApps();
76-
return relatedApps.some((app) => app.platform === 'webapp');
75+
try {
76+
const relatedApps = await navigator.getInstalledRelatedApps();
77+
return relatedApps.some((app) => app.platform === 'webapp');
78+
} catch (e) {
79+
// Error might be thrown when Docusaurus is embedded in an iframe:
80+
// registerSW failed DOMException: Failed to execute 'getInstalledRelatedApps' on 'Navigator': getInstalledRelatedApps() is only supported in top-level browsing contexts.
81+
return false;
82+
}
7783
}
7884
function isStandaloneDisplayMode() {
7985
return window.matchMedia('(display-mode: standalone)').matches;

packages/docusaurus-plugin-sitemap/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
"tslib": "^2.5.0"
3030
},
3131
"peerDependencies": {
32-
"react": "^16.8.4 || ^17.0.0",
33-
"react-dom": "^16.8.4 || ^17.0.0"
32+
"react": "^18.0.0",
33+
"react-dom": "^18.0.0"
3434
},
3535
"engines": {
3636
"node": ">=16.14"

packages/docusaurus-preset-classic/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
"@docusaurus/types": "^3.0.0-alpha.0"
3434
},
3535
"peerDependencies": {
36-
"react": "^16.8.4 || ^17.0.0",
37-
"react-dom": "^16.8.4 || ^17.0.0"
36+
"react": "^18.0.0",
37+
"react-dom": "^18.0.0"
3838
},
3939
"engines": {
4040
"node": ">=16.14"

packages/docusaurus-theme-classic/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
"@types/prismjs": "^1.26.0",
5353
"@types/rtlcss": "^3.5.0",
5454
"fs-extra": "^11.1.0",
55-
"react-test-renderer": "^17.0.2",
55+
"react-test-renderer": "^18.0.0",
5656
"utility-types": "^3.10.0"
5757
},
5858
"peerDependencies": {
59-
"react": "^16.8.4 || ^17.0.0",
60-
"react-dom": "^16.8.4 || ^17.0.0"
59+
"react": "^18.0.0",
60+
"react-dom": "^18.0.0"
6161
},
6262
"engines": {
6363
"node": ">=16.14"

packages/docusaurus-theme-common/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
"lodash": "^4.17.21"
5555
},
5656
"peerDependencies": {
57-
"react": "^16.8.4 || ^17.0.0",
58-
"react-dom": "^16.8.4 || ^17.0.0"
57+
"react": "^18.0.0",
58+
"react-dom": "^18.0.0"
5959
},
6060
"engines": {
6161
"node": ">=16.14"

packages/docusaurus-theme-common/src/components/Collapsible/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import React, {
1010
useEffect,
1111
useRef,
1212
useCallback,
13-
useLayoutEffect,
1413
type RefObject,
1514
type Dispatch,
1615
type SetStateAction,
1716
type ReactNode,
1817
} from 'react';
1918
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
19+
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
2020
import {prefersReducedMotion} from '../../utils/accessibilityUtils';
2121

2222
const DefaultAnimationEasing = 'ease-in-out';
@@ -231,13 +231,13 @@ function CollapsibleLazy({collapsed, ...props}: CollapsibleBaseProps) {
231231
// Updated in effect so that first expansion transition can work
232232
const [lazyCollapsed, setLazyCollapsed] = useState(collapsed);
233233

234-
useLayoutEffect(() => {
234+
useIsomorphicLayoutEffect(() => {
235235
if (!collapsed) {
236236
setMounted(true);
237237
}
238238
}, [collapsed]);
239239

240-
useLayoutEffect(() => {
240+
useIsomorphicLayoutEffect(() => {
241241
if (mounted) {
242242
setLazyCollapsed(collapsed);
243243
}

packages/docusaurus-theme-common/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export {ThemeClassNames} from './utils/ThemeClassNames';
4848
export {prefersReducedMotion} from './utils/accessibilityUtils';
4949

5050
export {
51-
useIsomorphicLayoutEffect,
5251
useEvent,
5352
usePrevious,
5453
composeProviders,

packages/docusaurus-theme-common/src/utils/reactUtils.tsx

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,12 @@
77

88
import React, {
99
useCallback,
10-
useEffect,
11-
useLayoutEffect,
1210
useMemo,
1311
useRef,
1412
type ComponentType,
1513
type ReactNode,
1614
} from 'react';
17-
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
18-
19-
/**
20-
* This hook is like `useLayoutEffect`, but without the SSR warning.
21-
* It seems hacky but it's used in many React libs (Redux, Formik...).
22-
* Also mentioned here: https://github.com/facebook/react/issues/16956
23-
*
24-
* It is useful when you need to update a ref as soon as possible after a React
25-
* render (before `useEffect`).
26-
*/
27-
export const useIsomorphicLayoutEffect = ExecutionEnvironment.canUseDOM
28-
? useLayoutEffect
29-
: useEffect;
15+
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
3016

3117
/**
3218
* Temporary userland implementation until an official hook is implemented

0 commit comments

Comments
 (0)