Skip to content

Commit

Permalink
make our website run on React 19
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Dec 13, 2024
1 parent b7078d7 commit c5181dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion admin/test-bad-package/README.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {version as ReactVersion} from 'react';
import {version as ReactDOMVersion} from 'react-dom';

export function TestComponent() {
const expectedVersion = 18;
const expectedVersion = 19;
if (!ReactVersion.startsWith(`${expectedVersion}`)) {
throw new Error(
`'test-bad-package/README.mdx' is rendered with bad React version: ${ReactVersion}`,
Expand Down
23 changes: 14 additions & 9 deletions packages/docusaurus/src/webpack/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,19 @@ const LibrariesToTranspileRegex = new RegExp(
LibrariesToTranspile.map((libName) => `(node_modules/${libName})`).join('|'),
);

const ReactAliases: Record<string, string> = process.env
.DOCUSAURUS_NO_REACT_ALIASES
? {}
: {
react: path.dirname(require.resolve('react/package.json')),
'react-dom': path.dirname(require.resolve('react-dom/package.json')),
'@mdx-js/react': path.dirname(require.resolve('@mdx-js/react')),
};
function getReactAliases(siteDir: string): Record<string, string> {
// Escape hatch
if (process.env.DOCUSAURUS_NO_REACT_ALIASES) {
return {};
}
const resolveSitePkg = (id: string) =>
require.resolve(id, {paths: [siteDir]});
return {
react: path.dirname(resolveSitePkg('react/package.json')),
'react-dom': path.dirname(resolveSitePkg('react-dom/package.json')),
'@mdx-js/react': path.dirname(resolveSitePkg('@mdx-js/react')),
};
}

export function excludeJS(modulePath: string): boolean {
// Always transpile client dir
Expand Down Expand Up @@ -186,7 +191,7 @@ export async function createBaseConfig({
process.cwd(),
],
alias: {
...ReactAliases,
...getReactAliases(siteDir),
'@site': siteDir,
'@generated': generatedFilesDir,
...(await loadDocusaurusAliases()),
Expand Down
4 changes: 2 additions & 2 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
"netlify-plugin-cache": "^1.0.3",
"pure-react-carousel": "^1.30.1",
"raw-loader": "^4.0.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"react-lite-youtube-embed": "^2.3.52",
"react-medium-image-zoom": "^5.1.6",
"recma-mdx-displayname": "^0.4.1",
Expand Down

0 comments on commit c5181dd

Please sign in to comment.