Skip to content

Commit 3502a60

Browse files
committed
upgrade to remix v2
1 parent 40263ae commit 3502a60

32 files changed

+7339
-9324
lines changed

app/entry.server.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { PassThrough } from "stream";
21
import type { EntryContext } from "@remix-run/node";
3-
import { Response } from "@remix-run/node";
2+
import { createReadableStreamFromReadable } from "@remix-run/node";
43
import { RemixServer } from "@remix-run/react";
54
import isbot from "isbot";
5+
import { PassThrough } from "node:stream";
66
import { renderToPipeableStream } from "react-dom/server";
77

88
const ABORT_DELAY = 5000;
@@ -29,7 +29,7 @@ export default function handleRequest(
2929
responseHeaders.set("Content-Type", "text/html");
3030

3131
resolve(
32-
new Response(body, {
32+
new Response(createReadableStreamFromReadable(body), {
3333
headers: responseHeaders,
3434
status: didError ? 500 : responseStatusCode,
3535
})

app/root.tsx

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { LinksFunction, LoaderArgs, MetaFunction } from "@remix-run/node";
1+
import type { LinksFunction, LoaderFunctionArgs } from "@remix-run/node";
22
import { json } from "@remix-run/node";
33
import {
44
Links,
@@ -9,20 +9,12 @@ import {
99
ScrollRestoration,
1010
} from "@remix-run/react";
1111

12-
import tailwindStylesheetUrl from "./styles/tailwind.css";
1312
import { getUser } from "./session.server";
13+
import styles from "~/tailwind.css?url";
1414

15-
export const links: LinksFunction = () => {
16-
return [{ rel: "stylesheet", href: tailwindStylesheetUrl }];
17-
};
15+
export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];
1816

19-
export const meta: MetaFunction = () => ({
20-
charset: "utf-8",
21-
title: "Remix Notes",
22-
viewport: "width=device-width,initial-scale=1",
23-
});
24-
25-
export async function loader({ request }: LoaderArgs) {
17+
export async function loader({ request }: LoaderFunctionArgs) {
2618
return json({
2719
user: await getUser(request),
2820
});
File renamed without changes.

app/routes/healthcheck.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
2-
import type { LoaderArgs } from "@remix-run/node";
32

3+
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
44
import { prisma } from "~/db.server";
55

6-
export async function loader({ request }: LoaderArgs) {
6+
export async function loader({ request }: LoaderFunctionArgs) {
77
const host =
88
request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");
99

app/routes/join.tsx

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import type { ActionArgs, LoaderArgs, MetaFunction } from "@remix-run/node";
1+
import type {
2+
ActionFunctionArgs,
3+
LoaderFunctionArgs,
4+
MetaFunction,
5+
} from "@remix-run/node";
26
import { json, redirect } from "@remix-run/node";
37
import { Form, Link, useActionData, useSearchParams } from "@remix-run/react";
48
import * as React from "react";
@@ -8,13 +12,13 @@ import { getUserId, createUserSession } from "~/session.server";
812
import { createUser, getUserByEmail } from "~/models/user.server";
913
import { safeRedirect, validateEmail } from "~/utils";
1014

11-
export async function loader({ request }: LoaderArgs) {
15+
export async function loader({ request }: LoaderFunctionArgs) {
1216
const userId = await getUserId(request);
1317
if (userId) return redirect("/");
1418
return json({});
1519
}
1620

17-
export async function action({ request }: ActionArgs) {
21+
export async function action({ request }: ActionFunctionArgs) {
1822
const formData = await request.formData();
1923
const email = formData.get("email");
2024
const password = formData.get("password");
@@ -65,9 +69,11 @@ export async function action({ request }: ActionArgs) {
6569
}
6670

6771
export const meta: MetaFunction = () => {
68-
return {
69-
title: "Sign Up",
70-
};
72+
return [
73+
{
74+
title: "Sign Up",
75+
},
76+
];
7177
};
7278

7379
export default function Join() {

app/routes/login.tsx

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ActionArgs, LoaderArgs, MetaFunction } from "@remix-run/node";
1+
import type { LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
22
import { json, redirect } from "@remix-run/node";
33
import { Form, Link, useActionData, useSearchParams } from "@remix-run/react";
44
import * as React from "react";
@@ -7,17 +7,17 @@ import { createUserSession, getUserId } from "~/session.server";
77
import { verifyLogin } from "~/models/user.server";
88
import { safeRedirect, validateEmail } from "~/utils";
99

10-
export async function loader({ request }: LoaderArgs) {
10+
export async function loader({ request }: LoaderFunctionArgs) {
1111
const userId = await getUserId(request);
1212
if (userId) return redirect("/");
1313
return json({});
1414
}
1515

16-
export async function action({ request }: ActionArgs) {
16+
export async function action({ request }: LoaderFunctionArgs) {
1717
const formData = await request.formData();
1818
const email = formData.get("email");
1919
const password = formData.get("password");
20-
const redirectTo = safeRedirect(formData.get("redirectTo"), "/notes");
20+
const redirectTo = safeRedirect(formData.get("redirectTo"), "/posts");
2121
const remember = formData.get("remember");
2222

2323
if (!validateEmail(email)) {
@@ -59,14 +59,16 @@ export async function action({ request }: ActionArgs) {
5959
}
6060

6161
export const meta: MetaFunction = () => {
62-
return {
63-
title: "Login",
64-
};
62+
return [
63+
{
64+
title: "Login",
65+
},
66+
];
6567
};
6668

6769
export default function LoginPage() {
6870
const [searchParams] = useSearchParams();
69-
const redirectTo = searchParams.get("redirectTo") || "/notes";
71+
const redirectTo = searchParams.get("redirectTo") || "/posts";
7072
const actionData = useActionData<typeof action>();
7173
const emailRef = React.useRef<HTMLInputElement>(null);
7274
const passwordRef = React.useRef<HTMLInputElement>(null);

app/routes/logout.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import type { ActionArgs } from "@remix-run/node";
1+
import type { ActionFunctionArgs } from "@remix-run/node";
22
import { redirect } from "@remix-run/node";
33

44
import { logout } from "~/session.server";
55

6-
export async function action({ request }: ActionArgs) {
6+
export async function action({ request }: ActionFunctionArgs) {
77
return logout(request);
88
}
99

app/routes/posts/$postId.tsx renamed to app/routes/posts.$postId.tsx

+4-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { ActionArgs, LoaderArgs } from "@remix-run/node";
1+
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
22
import { json, redirect } from "@remix-run/node";
3-
import { Form, useCatch, useLoaderData } from "@remix-run/react";
3+
import { Form, useLoaderData } from "@remix-run/react";
44
import invariant from "tiny-invariant";
55
import {
66
deletePost,
@@ -11,7 +11,7 @@ import {
1111

1212
import { requireUserId } from "~/session.server";
1313

14-
export async function loader({ request, params }: LoaderArgs) {
14+
export async function loader({ request, params }: LoaderFunctionArgs) {
1515
const userId = await requireUserId(request);
1616
invariant(params.postId, "await not found");
1717

@@ -22,7 +22,7 @@ export async function loader({ request, params }: LoaderArgs) {
2222
return json({ post });
2323
}
2424

25-
export async function action({ request, params }: ActionArgs) {
25+
export async function action({ request, params }: ActionFunctionArgs) {
2626
const userId = await requireUserId(request);
2727
invariant(params.postId, "postId not found");
2828

@@ -86,13 +86,3 @@ export function ErrorBoundary({ error }: { error: Error }) {
8686

8787
return <div>An unexpected error occurred: {error.message}</div>;
8888
}
89-
90-
export function CatchBoundary() {
91-
const caught = useCatch();
92-
93-
if (caught.status === 404) {
94-
return <div>Post not found</div>;
95-
}
96-
97-
throw new Error(`Unexpected caught response with status: ${caught.status}`);
98-
}
File renamed without changes.

app/routes/posts/new.tsx renamed to app/routes/posts.new.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import type { ActionArgs } from "@remix-run/node";
2-
import { json, redirect } from "@remix-run/node";
1+
import { type ActionFunctionArgs, json, redirect } from "@remix-run/node";
32
import { Form, useActionData } from "@remix-run/react";
43
import * as React from "react";
54
import { createPost } from "~/models/post.server";
65

76
import { requireUserId } from "~/session.server";
87

9-
export async function action({ request }: ActionArgs) {
8+
export async function action({ request }: ActionFunctionArgs) {
109
const userId = await requireUserId(request);
1110

1211
const formData = await request.formData();

app/routes/posts.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import type { LoaderArgs } from "@remix-run/node";
1+
import type { LoaderFunctionArgs } from "@remix-run/node";
22
import { json } from "@remix-run/node";
33
import { Form, Link, NavLink, Outlet, useLoaderData } from "@remix-run/react";
44
import { getPosts } from "~/models/post.server";
55
import { requireUserId } from "~/session.server";
66
import { useUser } from "~/utils";
77

8-
export async function loader({ request }: LoaderArgs) {
8+
export async function loader({ request }: LoaderFunctionArgs) {
99
const userId = await requireUserId(request);
1010
const posts = await getPosts({ userId });
1111
return json({ posts });

app/tailwind.css

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@tailwind base;
2+
@tailwind components;
3+
@tailwind utilities;

app/utils.test.ts

-13
This file was deleted.

app/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export function useMatchesData(
4141
() => matchingRoutes.find((route) => route.id === id),
4242
[matchingRoutes, id]
4343
);
44-
return route?.data;
44+
return route?.data as Record<string, unknown> | undefined;
4545
}
4646

4747
function isUser(user: any): user is User {

cypress/.eslintrc.js

-6
This file was deleted.

cypress/e2e/smoke.cy.ts

-51
This file was deleted.

cypress/fixtures/example.json

-5
This file was deleted.

0 commit comments

Comments
 (0)