Skip to content

Commit 2b6df0b

Browse files
authoredSep 6, 2023
Upgrade to Next 13 (#24)
* upgrades to next.js 13 * fixes typescript errors * fixes some lint warnings * updates node versions
1 parent 3b8463d commit 2b6df0b

16 files changed

+332
-276
lines changed
 

Diff for: ‎.eslintrc.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"extends": "next/core-web-vitals"
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"@next/next/no-img-element": "off"
5+
}
36
}

Diff for: ‎.github/workflows/build.yml

+12-13
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,25 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ main ]
8+
branches: [main]
99
pull_request:
10-
branches: [ main ]
10+
branches: [main]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
strategy:
1817
matrix:
19-
node-version: [14.x, 16.x]
18+
node-version: [16.x, 18.x]
2019

2120
steps:
22-
- uses: actions/checkout@v2
23-
- name: Use Node.js ${{ matrix.node-version }}
24-
uses: actions/setup-node@v2
25-
with:
26-
node-version: ${{ matrix.node-version }}
27-
cache: 'npm'
28-
- run: npm i
29-
- run: npm run lint
30-
- run: npm run build
21+
- uses: actions/checkout@v2
22+
- name: Use Node.js ${{ matrix.node-version }}
23+
uses: actions/setup-node@v2
24+
with:
25+
node-version: ${{ matrix.node-version }}
26+
cache: "npm"
27+
- run: npm i
28+
- run: npm run lint
29+
- run: npm run build

Diff for: ‎components/footer.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ import Logo from "./logo";
44
export default function Footer() {
55
return (
66
<div className="mx-4 my-10 flex items-center justify-center">
7-
<Link href="/">
8-
<a aria-label="Gistdoc" className="h-8 w-8">
9-
<Logo />
10-
</a>
7+
<Link href="/" aria-label="Gistdoc" className="h-8 w-8" passHref>
8+
<Logo />
119
</Link>
1210
</div>
1311
);

Diff for: ‎components/gist-document/gist-document.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function GistDocument({
2222
const filenames = Object.keys(files);
2323
const markdownFile = findMarkdownFile(filenames);
2424

25-
if (!markdownFile) return <UnsupportedGist />;
25+
if (!markdownFile || !gistData) return <UnsupportedGist />;
2626

2727
const { content } = files[markdownFile];
2828

Diff for: ‎components/link/link-with-avatar.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import Image from "next/image";
12
import Link, { LinkProps } from "./link";
23

34
interface LinkWithAvatarProps extends LinkProps {
@@ -10,19 +11,22 @@ export default function LinkWithAvatar({
1011
alt,
1112
href,
1213
children,
14+
variant = "subtle",
1315
...rest
1416
}: LinkWithAvatarProps) {
1517
return (
1618
<Link
1719
href={href}
18-
variant="subtle"
20+
variant={variant}
1921
className="flex items-center text-gray-500"
2022
{...rest}
2123
>
2224
<img
2325
src={avatarUrl}
2426
alt={alt}
25-
className="w-[28px] h-[28px] rounded-full mr-2"
27+
width={28}
28+
height={28}
29+
className="rounded-full mr-2"
2630
/>
2731
{children}
2832
</Link>

Diff for: ‎components/link/link.tsx

+12-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
import type { Url } from "next/dist/shared/lib/router/router";
12
import NextLink, { LinkProps as NextLinkProps } from "next/link";
23
import { AnchorHTMLAttributes } from "react";
34

4-
export interface LinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {
5+
export type LinkProps = {
56
variant?: "subtle" | "button" | "unstyled";
6-
}
7+
href?: Url;
8+
} & Omit<NextLinkProps, "href"> &
9+
AnchorHTMLAttributes<HTMLAnchorElement>;
710

811
const variantClasses = {
912
normal: "text-sky-600 no-underline hover:underline",
@@ -15,18 +18,18 @@ const variantClasses = {
1518

1619
export default function Link({
1720
href,
18-
variant,
21+
variant = "unstyled",
1922
className,
2023
...props
2124
}: React.PropsWithChildren<LinkProps>) {
2225
const baseClasses = variantClasses[variant] ?? variantClasses.normal;
26+
const LinkComponent = href ? NextLink : "a";
2327

2428
return (
25-
<NextLink href={href}>
26-
<a
27-
{...props}
28-
className={`${baseClasses}${className ? ` ${className}` : ""}`}
29-
/>
30-
</NextLink>
29+
<LinkComponent
30+
href={href || "#"}
31+
{...props}
32+
className={`${baseClasses}${className ? ` ${className}` : ""}`}
33+
/>
3134
);
3235
}

Diff for: ‎components/markdown/CodeBlock.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ export default function CodeBlock({
3030
);
3131
}
3232

33-
const language = className.replace("language-", "");
33+
const language = className?.replace("language-", "");
3434
const codeToParse = String(children?.[0] || "");
35+
const child = language ? (
36+
<SyntaxHighlighter language={language} code={codeToParse} />
37+
) : (
38+
codeToParse
39+
);
3540

3641
return (
3742
<code className={className}>
38-
<Suspense fallback={codeToParse}>
39-
<SyntaxHighlighter language={language} code={codeToParse} />
40-
</Suspense>
43+
<Suspense fallback={codeToParse}>{child}</Suspense>
4144
</code>
4245
);
4346
}

Diff for: ‎components/syntax-highlighter/syntax-highlighter.tsx

+8-3
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ export default function SyntaxHighlighter({
2828
const languageConfig = languages.find((langConfig) =>
2929
langConfig.alias.includes(language)
3030
);
31-
const block = useRef();
31+
const block = useRef<HTMLDivElement>(null);
3232

3333
useEffect(() => {
3434
let mounted = true;
3535

3636
(async function () {
37-
const languageSupport = await languageConfig.load();
37+
const languageSupport = languageConfig
38+
? await languageConfig.load()
39+
: null;
3840

3941
if (block.current && mounted) {
4042
const extensions = [
@@ -58,10 +60,13 @@ export default function SyntaxHighlighter({
5860
syntaxHighlighting(defaultHighlightStyle),
5961
syntaxHighlighting(highlightStyle),
6062
highlightSpecialChars(),
61-
languageSupport,
6263
EditorState.tabSize.of(2),
6364
];
6465

66+
if (languageSupport) {
67+
extensions.push(languageSupport);
68+
}
69+
6570
let view = new EditorView({
6671
doc: code.trimEnd(),
6772
extensions,

Diff for: ‎components/theme-toggle/theme-toggle.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default function ThemeToggle() {
88
// This is required to prevent the animation from playing on
99
// initial mount as well as update the aria-label.
1010
const changedRef = useRef(false);
11-
const [colorScheme, setColorScheme] = useState(null);
11+
const [colorScheme, setColorScheme] = useState<"dark" | "light" | null>(null);
1212
const handleChange = useCallback(
1313
(ev) => {
1414
const colorScheme = resolveColorScheme(ev.target.checked);
@@ -56,7 +56,7 @@ export default function ThemeToggle() {
5656
// It's set to auto for the first time since the user didn't
5757
// actually change it and we set the theme automatically based
5858
// on preference.
59-
aria-label={hasThemeChanged ? colorScheme : "auto"}
59+
aria-label={(hasThemeChanged && colorScheme) || "auto"}
6060
aria-live="polite"
6161
id="theme-toggle"
6262
className={`sr-only peer`}

Diff for: ‎constants.js

-9
This file was deleted.

Diff for: ‎constants.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const constants = {
2+
GITHUB_API_BASE_URL: "https://api.github.com",
3+
GIST: {
4+
HOME: "59ff2b40f69fc7f4ea2fdd6b1a044648",
5+
CHANGELOG: "2ff7302367044178af3eeaee4384a4ba",
6+
},
7+
};
8+
9+
export default constants;

Diff for: ‎next-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/basic-features/typescript for more information.

Diff for: ‎package-lock.json

+254-217
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: ‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@codemirror/view": "^6.0.2",
1515
"@lezer/highlight": "^1.0.0",
1616
"dayjs": "^1.10.7",
17-
"next": "^12.1.6",
17+
"next": "^13.4.19",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0",
2020
"react-markdown": "^7.1.2",

Diff for: ‎tailwind.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
darkMode: "class",
33
content: [
4+
"./app/**/*.{js,ts,jsx,tsx,mdx}",
45
"./pages/**/*.{js,ts,jsx,tsx}",
56
"./components/**/*.{js,ts,jsx,tsx}",
67
],

Diff for: ‎tsconfig.json

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"compilerOptions": {
33
"target": "es5",
4-
"lib": [
5-
"dom",
6-
"dom.iterable",
7-
"esnext"
8-
],
4+
"lib": ["dom", "dom.iterable", "esnext"],
95
"allowJs": true,
106
"skipLibCheck": true,
117
"strict": false,
@@ -17,14 +13,20 @@
1713
"moduleResolution": "node",
1814
"resolveJsonModule": true,
1915
"isolatedModules": true,
20-
"jsx": "preserve"
16+
"jsx": "preserve",
17+
"plugins": [
18+
{
19+
"name": "next"
20+
}
21+
],
22+
"strictNullChecks": true
2123
},
2224
"include": [
2325
"next-env.d.ts",
26+
"**/*.js",
2427
"**/*.ts",
25-
"**/*.tsx"
28+
"**/*.tsx",
29+
".next/types/**/*.ts"
2630
],
27-
"exclude": [
28-
"node_modules"
29-
]
31+
"exclude": ["node_modules"]
3032
}

1 commit comments

Comments
 (1)

vercel[bot] commented on Sep 6, 2023

@vercel[bot]
Please sign in to comment.