Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: React 18 + automatic JSX runtime + build --dev #8961

Merged
merged 33 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f21dd48
Upgrade React-18 dependencies
slorber May 5, 2023
9688b83
Update client entrypoint to React 18 APIs
slorber May 5, 2023
5f4bc6c
Add React-18 API to render static string on the server
slorber May 5, 2023
1bc3d2d
Add React-18 test page
slorber May 5, 2023
3655fa6
Merge branch 'main' into slorber/react-18
slorber May 12, 2023
1ff6fa2
Add useIsomorphicLayoutEffect in core (until warning is really removed)
slorber May 12, 2023
657e8a9
fix little server warning
slorber May 12, 2023
f9574c9
Fix hydration mismatch due to SSR template adding line break
slorber May 12, 2023
5a3df4d
Add secret env variable to debug build hydration issues: DOCUSAURUS_D…
slorber May 12, 2023
135f9a5
update snapshots
slorber May 12, 2023
cb69d41
Merge branch 'main' into slorber/react-18
slorber May 15, 2023
275e211
Fix hydration issues due to BaseUrlIssueBanner
slorber May 15, 2023
381e206
minor quote change
slorber May 15, 2023
9a5bfb3
Merge branch 'main' into slorber/react-18
slorber May 30, 2023
ce63c42
replace endiliey/react-ideal-image with my own fork
slorber May 30, 2023
2ade4ad
Merge branch 'main' into slorber/react-18
slorber May 31, 2023
1436bd9
remove dead code
slorber Jun 2, 2023
a2904aa
Upgrade to @slorber/react-ideal-image after React 18 fixes
slorber Jun 2, 2023
95c1ee6
fix CustomDogfoodNavbarItem little trailingSlash sensitivity
slorber Jun 2, 2023
6a9c398
remove annoying pwa debugging logs in deployPreview
slorber Jun 2, 2023
b53423d
PWA: add failsafe try/catch when calling getInstalledRelatedApps to a…
slorber Jun 2, 2023
a94abb1
Quickfix for hooks SSR/hydration tests
slorber Jun 2, 2023
255fd7d
Add useful test comment for later
slorber Jun 2, 2023
fbfe18c
ignore TS error
slorber Jun 2, 2023
4777d04
restore required mdx template deps
slorber Jun 2, 2023
396b7e4
lockfile
slorber Jun 2, 2023
4188ec3
website ts config update
slorber Jun 2, 2023
599f9c1
ConfigTabs => code blocks shouldn't be in <p> tags, this leads to hyd…
slorber Jun 8, 2023
8d72c70
Use automatic JSX runtime
slorber Jun 8, 2023
127a931
Fix website TS config for automatic JSX runtime
slorber Jun 8, 2023
2692c9d
remove useless package entries typo
slorber Jun 8, 2023
275c0bb
Add proper build --dev mode
slorber Jun 8, 2023
66e0aa1
better onRecoverableError error message
slorber Jun 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ module.exports = {
'@docusaurus',
],
rules: {
'react/jsx-uses-react': OFF, // JSX runtime: automatic
'react/react-in-jsx-scope': OFF, // JSX runtime: automatic
'array-callback-return': WARNING,
camelcase: WARNING,
'class-methods-use-this': OFF, // It's a way of allowing private variables.
Expand Down Expand Up @@ -259,6 +261,9 @@ module.exports = {
},
{pattern: '@jest/globals', group: 'builtin', position: 'before'},
{pattern: 'react', group: 'builtin', position: 'before'},
{pattern: 'react-dom', group: 'builtin', position: 'before'},
{pattern: 'react-dom/**', group: 'builtin', position: 'before'},
{pattern: 'stream', group: 'builtin', position: 'before'},
{pattern: 'fs-extra', group: 'builtin'},
{pattern: 'lodash', group: 'external', position: 'before'},
{pattern: 'clsx', group: 'external', position: 'before'},
Expand Down
1 change: 1 addition & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ignorePatterns = [
export default {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
verbose: true,
setupFiles: ['./jest/setup.js'],
testEnvironmentOptions: {
url: 'https://docusaurus.io/',
},
Expand Down
11 changes: 11 additions & 0 deletions jest/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {TextEncoder} from 'util';

// Required for RTL renderHook SSR tests with React-18
// See also https://github.com/testing-library/react-testing-library/issues/1120#issuecomment-1516132279
global.TextEncoder = TextEncoder;
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@
"lint-staged": "^13.1.2",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.4",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react-helmet-async": "^1.3.0",
"react-test-renderer": "^17.0.2",
"react-test-renderer": "^18.0.0",
"remark-parse": "^8.0.2",
"rimraf": "^3.0.2",
"sharp": "^0.31.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^2.1.5",
"@mdx-js/react": "^2.3.0",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/create-docusaurus/templates/classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"dependencies": {
"@docusaurus/core": "^3.0.0-alpha.0",
"@docusaurus/preset-classic": "^3.0.0-alpha.0",
"@mdx-js/react": "^2.1.5",
"@mdx-js/react": "^2.3.0",
"clsx": "^1.2.1",
"prism-react-renderer": "^1.3.5",
"react": "^17.0.2",
"react-dom": "^17.0.2"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"devDependencies": {
"@docusaurus/module-type-aliases": "^3.0.0-alpha.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-mdx-loader/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
"unist-util-remove-position": "^3.0.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-module-type-aliases/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,12 @@ declare module '@docusaurus/router' {
export {useHistory, useLocation, Redirect, matchPath} from 'react-router-dom';
}

declare module '@docusaurus/useIsomorphicLayoutEffect' {
import {useLayoutEffect} from 'react';

export = useLayoutEffect;
}

declare module '@docusaurus/useDocusaurusContext' {
import type {DocusaurusContext} from '@docusaurus/types';

Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-client-redirects/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
"@docusaurus/types": "^3.0.0-alpha.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"webpack": "^5.76.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
"shelljs": "^0.8.5"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-content-pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"webpack": "^5.76.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-debug/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-gtag/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-google-tag-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-plugin-ideal-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@docusaurus/theme-translations": "^3.0.0-alpha.0",
"@docusaurus/types": "^3.0.0-alpha.0",
"@docusaurus/utils-validation": "^3.0.0-alpha.0",
"@endiliey/react-ideal-image": "^0.0.11",
"@slorber/react-ideal-image": "^0.0.12",
"react-waypoint": "^10.3.0",
"sharp": "^0.31.3",
"tslib": "^2.5.0",
Expand All @@ -38,8 +38,8 @@
},
"peerDependencies": {
"jimp": "*",
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"peerDependenciesMeta": {
"jimp": {
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus-plugin-ideal-image/src/deps.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Note: the original type definition is WRONG. getIcon & getMessage receive
* full state object.
*/
declare module '@endiliey/react-ideal-image' {
declare module '@slorber/react-ideal-image' {
import type {ComponentProps, ComponentType, CSSProperties} from 'react';

export type LoadingState = 'initial' | 'loading' | 'loaded' | 'error';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';
import ReactIdealImage, {
type IconKey,
type State,
} from '@endiliey/react-ideal-image';
} from '@slorber/react-ideal-image';
import {translate} from '@docusaurus/Translate';

import type {Props} from '@theme/IdealImage';
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"fs-extra": "^11.1.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
10 changes: 8 additions & 2 deletions packages/docusaurus-plugin-pwa/src/registerSw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,14 @@ async function getIsAppInstalledRelatedApps() {
if (!('getInstalledRelatedApps' in window.navigator)) {
return false;
}
const relatedApps = await navigator.getInstalledRelatedApps();
return relatedApps.some((app) => app.platform === 'webapp');
try {
const relatedApps = await navigator.getInstalledRelatedApps();
return relatedApps.some((app) => app.platform === 'webapp');
} catch (e) {
// Error might be thrown when Docusaurus is embedded in an iframe:
// registerSW failed DOMException: Failed to execute 'getInstalledRelatedApps' on 'Navigator': getInstalledRelatedApps() is only supported in top-level browsing contexts.
return false;
}
}
function isStandaloneDisplayMode() {
return window.matchMedia('(display-mode: standalone)').matches;
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-plugin-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
"tslib": "^2.5.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-preset-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"@docusaurus/types": "^3.0.0-alpha.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
6 changes: 3 additions & 3 deletions packages/docusaurus-theme-classic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"@types/prismjs": "^1.26.0",
"@types/rtlcss": "^3.5.0",
"fs-extra": "^11.1.0",
"react-test-renderer": "^17.0.2",
"react-test-renderer": "^18.0.0",
"utility-types": "^3.10.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
4 changes: 2 additions & 2 deletions packages/docusaurus-theme-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
"lodash": "^4.17.21"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0",
"react-dom": "^16.8.4 || ^17.0.0"
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"engines": {
"node": ">=16.14"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import React, {
useEffect,
useRef,
useCallback,
useLayoutEffect,
type RefObject,
type Dispatch,
type SetStateAction,
type ReactNode,
} from 'react';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
import {prefersReducedMotion} from '../../utils/accessibilityUtils';

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

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
if (!collapsed) {
setMounted(true);
}
}, [collapsed]);

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
if (mounted) {
setLazyCollapsed(collapsed);
}
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-theme-common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export {ThemeClassNames} from './utils/ThemeClassNames';
export {prefersReducedMotion} from './utils/accessibilityUtils';

export {
useIsomorphicLayoutEffect,
useEvent,
usePrevious,
composeProviders,
Expand Down
16 changes: 1 addition & 15 deletions packages/docusaurus-theme-common/src/utils/reactUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,12 @@

import React, {
useCallback,
useEffect,
useLayoutEffect,
useMemo,
useRef,
type ComponentType,
type ReactNode,
} from 'react';
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';

/**
* This hook is like `useLayoutEffect`, but without the SSR warning.
* It seems hacky but it's used in many React libs (Redux, Formik...).
* Also mentioned here: https://github.com/facebook/react/issues/16956
*
* It is useful when you need to update a ref as soon as possible after a React
* render (before `useEffect`).
*/
export const useIsomorphicLayoutEffect = ExecutionEnvironment.canUseDOM
? useLayoutEffect
: useEffect;
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';

/**
* Temporary userland implementation until an official hook is implemented
Expand Down