Skip to content

Commit

Permalink
Upgarde to Next.js 15
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmoroz committed Oct 25, 2024
1 parent b37dfc9 commit fa6480e
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 208 deletions.
6 changes: 0 additions & 6 deletions docs/config.ts

This file was deleted.

25 changes: 10 additions & 15 deletions docs/next.config.mjs → docs/next.config.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
// @ts-check
import * as path from 'path';
import * as url from 'url';
import * as fs from 'fs';
// eslint-disable-next-line no-restricted-imports
import withDocsInfra from '@mui/monorepo/docs/nextConfigDocsInfra.js';
import withDocsInfra from '@mui/monorepo/docs/nextConfigDocsInfra';
import { NextConfig } from 'next';

const currentDirectory = url.fileURLToPath(new URL('.', import.meta.url));
const workspaceRoot = path.resolve(currentDirectory, '../');

/**
* @returns {{version: string}}
*/
function loadPackageJson() {
function loadPackageJson(): { version: string } {
const pkgContent = fs.readFileSync(path.resolve(workspaceRoot, 'package.json'), 'utf8');
return JSON.parse(pkgContent);
}

const rootPackage = loadPackageJson();

/** @type {import('next').NextConfig} */
const nextConfig = {
const nextConfig: NextConfig = {
trailingSlash: false,
env: {
// docs-infra
Expand Down Expand Up @@ -56,15 +51,15 @@ const nextConfig = {
},
distDir: 'export',
transpilePackages: ['@mui/monorepo'],
...(process.env.NODE_ENV === 'production'
? {
output: 'export',
}
: {}),
...(process.env.NODE_ENV === 'production' ? { output: 'export' } : {}),
experimental: {
esmExternals: true,
workerThreads: false,
},
};

export default withDocsInfra(nextConfig);
const result = withDocsInfra(nextConfig);
// Delete deprecated options that come from `withDocsInfra()` and cause warnings
delete result.optimizeFonts;

export default result;
12 changes: 6 additions & 6 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@
"fast-glob": "^3.3.2",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"next": "^14.2.13",
"next": "15.0.1",
"postcss": "^8.4.47",
"postcss-import": "^16.1.0",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react": "19.0.0-rc-69d4b800-20241021",
"react-dom": "19.0.0-rc-69d4b800-20241021",
"react-error-boundary": "^4.0.13",
"react-is": "^18.3.1",
"react-is": "19.0.0-rc-69d4b800-20241021",
"react-router-dom": "^6.23.1",
"react-runner": "^1.0.5",
"react-simple-code-editor": "^0.13.1",
Expand All @@ -70,8 +70,8 @@
"@types/hast": "^3.0.4",
"@types/node": "^18.19.54",
"@types/prop-types": "^15.7.13",
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"@types/unist": "^3.0.3",
"chai": "^4.5.0",
"framer-motion": "^11.9.0",
Expand Down
4 changes: 4 additions & 0 deletions docs/shiki.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const shikiTheme = {
light: 'github-light-default',
dark: 'material-theme-ocean',
};
12 changes: 5 additions & 7 deletions docs/src/app/(content)/components/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ import { getApiReferenceData } from './getApiReferenceData';
const CATEGORY_SEGMENT = 'components';

interface Props {
params: {
params: Promise<{
slug: string;
};
}>;
}

function componentNameFromSlug(slug: string) {
return slug.replace('react-', '');
}

export default async function ComponentPage(props: Props) {
const {
params: { slug },
} = props;

const { slug } = await props.params;
const componentName = componentNameFromSlug(slug);

const { MDXContent, metadata, tableOfContents } = await getMarkdownPage(
Expand Down Expand Up @@ -93,7 +90,8 @@ export async function generateStaticParams() {
return getSlugs(`/${CATEGORY_SEGMENT}`).map((slug) => ({ slug }));
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata(props: Props): Promise<Metadata> {
const params = await props.params;
const { slug } = params;
const componentName = componentNameFromSlug(slug);
const { title = 'Components', description } = await getMarkdownPageMetadata(
Expand Down
9 changes: 2 additions & 7 deletions docs/src/app/(content)/getMarkdownPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import extractToc, { type Toc } from '@stefanprobst/rehype-extract-toc';
import exportToc from '@stefanprobst/rehype-extract-toc/mdx';
import { read as readVFile } from 'to-vfile';
import { matter } from 'vfile-matter';
import { config } from 'docs/config';
import { shikiTheme } from 'docs/shiki.config';

export const DATA_PATH = path.join(process.cwd(), 'data');

Expand Down Expand Up @@ -49,12 +49,7 @@ export const getMarkdownPage = async (basePath: string, slug: string) => {
} = await evaluate(mdxSource, {
...jsxRuntime,
remarkPlugins: [remarkGfm, remarkFrontmatter, remarkMdxFrontmatter],
rehypePlugins: [
[rehypePrettyCode, { theme: config.shikiThemes }],
rehypeSlug,
extractToc,
exportToc,
],
rehypePlugins: [[rehypePrettyCode, { theme: shikiTheme }], rehypeSlug, extractToc, exportToc],
});

return {
Expand Down
12 changes: 5 additions & 7 deletions docs/src/app/(content)/getting-started/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import { EditPageGithubLink } from 'docs/src/components/EditPageGithubLink';
const CATEGORY_SEGMENT = 'getting-started';

interface Props {
params: {
params: Promise<{
slug: string;
};
}>;
}

export default async function DocsPage(props: Props) {
const {
params: { slug },
} = props;

const { slug } = await props.params;
const { MDXContent, tableOfContents, metadata } = await getMarkdownPage(
CATEGORY_SEGMENT,
slug,
Expand Down Expand Up @@ -62,7 +59,8 @@ export async function generateStaticParams() {
return getSlugs(`/${CATEGORY_SEGMENT}`).map((slug) => ({ slug }));
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata(props: Props): Promise<Metadata> {
const params = await props.params;
const { slug } = params;
const { title = 'Getting started', description } = await getMarkdownPageMetadata(
CATEGORY_SEGMENT,
Expand Down
12 changes: 5 additions & 7 deletions docs/src/app/(content)/guides/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ import { EditPageGithubLink } from 'docs/src/components/EditPageGithubLink';
const CATEGORY_SEGMENT = 'guides';

interface Props {
params: {
params: Promise<{
slug: string;
};
}>;
}

export default async function DocsPage(props: Props) {
const {
params: { slug },
} = props;

const { slug } = await props.params;
const { MDXContent, tableOfContents, metadata } = await getMarkdownPage(
CATEGORY_SEGMENT,
slug,
Expand Down Expand Up @@ -62,7 +59,8 @@ export async function generateStaticParams() {
return getSlugs(`/${CATEGORY_SEGMENT}`).map((slug) => ({ slug }));
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata(props: Props): Promise<Metadata> {
const params = await props.params;
const { slug } = params;
const { title = 'Guides', description } = await getMarkdownPageMetadata(
CATEGORY_SEGMENT,
Expand Down
11 changes: 5 additions & 6 deletions docs/src/app/experiments/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,13 @@ import { readdir } from 'node:fs/promises';
import '../../../styles/style.css';

interface Props {
params: {
params: Promise<{
slug: string;
};
}>;
}

export default async function Page(props: Props) {
const {
params: { slug },
} = props;
const { slug } = await props.params;

try {
const Experiment = (await import(`../${slug}.tsx`)).default;
Expand All @@ -37,7 +35,8 @@ export async function generateStaticParams() {
.map((entry: Dirent) => ({ slug: basename(entry.name, extname(entry.name)) }));
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata(props: Props): Promise<Metadata> {
const params = await props.params;
const { slug } = params;

return {
Expand Down
11 changes: 5 additions & 6 deletions docs/src/app/playground/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@ import { readdir } from 'node:fs/promises';
import '../../../styles/style.css';

interface Props {
params: {
params: Promise<{
slug: string;
};
}>;
}

const DUMMY_SLUG = '_';

export default async function Page(props: Props) {
const {
params: { slug },
} = props;
const { slug } = await props.params;

if (slug === DUMMY_SLUG) {
notFound();
Expand Down Expand Up @@ -46,7 +44,8 @@ export async function generateStaticParams() {
return routes;
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
export async function generateMetadata(props: Props): Promise<Metadata> {
const params = await props.params;
const { slug } = params;

return {
Expand Down
10 changes: 5 additions & 5 deletions docs/src/components/demo/loadDemo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { existsSync, statSync } from 'node:fs';
import { readFile, readdir } from 'node:fs/promises';
import { basename, dirname, extname, resolve } from 'node:path';
import { codeToHtml } from 'shiki';
import { config } from 'docs/config';
import { shikiTheme } from 'docs/shiki.config';
import { DemoFile, DemoVariant } from 'docs/src/blocks/Demo';

const COMPONENTS_BASE_PATH = 'data/components';
Expand Down Expand Up @@ -66,7 +66,7 @@ async function getThemeFile(): Promise<DemoFile> {
const content = await readFile(path, 'utf-8');
const prettyContent = await codeToHtml(content, {
lang: 'css',
themes: config.shikiThemes,
themes: shikiTheme,
});

return {
Expand Down Expand Up @@ -101,7 +101,7 @@ async function loadSimpleDemo(path: string, variantName: string): Promise<DemoVa
const mainContent = await readFile(mainFilePath, 'utf-8');
const mainPrettyContent = await codeToHtml(mainContent, {
lang: `${mainFileLanguage}x`,
themes: config.shikiThemes,
themes: shikiTheme,
});

const localImports = getLocalImports(mainContent, dirname(mainFilePath));
Expand Down Expand Up @@ -129,7 +129,7 @@ async function loadSimpleDemo(path: string, variantName: string): Promise<DemoVa
const jsContent = await readFile(jsFilePath, 'utf-8');
const jsPrettyPromise = await codeToHtml(jsContent, {
lang: 'jsx',
themes: config.shikiThemes,
themes: shikiTheme,
});

const jsLocalImports = getLocalImports(mainContent, dirname(jsFilePath));
Expand Down Expand Up @@ -202,7 +202,7 @@ async function getDependencyFiles(paths: string[], preferTs: boolean): Promise<D
const content = await readFile(path, 'utf-8');
const prettyContent = await codeToHtml(content, {
lang: extension.slice(1),
themes: config.shikiThemes,
themes: shikiTheme,
});

const canHaveDependencies = type === 'ts' || type === 'js';
Expand Down
7 changes: 4 additions & 3 deletions docs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"extends": "../tsconfig.base.json",
"include": [
"data",
"data/*.tsx",
"data/*.ts",
"scripts/*.mts",
"src",
"types.d.ts",
"next-env.d.ts",
"next.config.mjs",
"next.config.ts",
".next/types/**/*.ts",
"export/types/**/*.ts",
"config.ts"
"shiki.config.ts"
],
"compilerOptions": {
"allowJs": true,
Expand Down
2 changes: 1 addition & 1 deletion docs/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// <reference types="gtag.js" />

declare module 'gtag.js';
declare module '@mui/monorepo/docs/nextConfigDocsInfra.js';
declare module '@mui/monorepo/docs/nextConfigDocsInfra';
Loading

0 comments on commit fa6480e

Please sign in to comment.