Skip to content

Commit

Permalink
feat: upgrade to Remix v2
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Sep 13, 2023
1 parent 8557499 commit 7b53ccb
Show file tree
Hide file tree
Showing 17 changed files with 69 additions and 153 deletions.
10 changes: 5 additions & 5 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { PassThrough } from "node:stream";

import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";
Expand Down Expand Up @@ -42,7 +42,7 @@ function handleBotRequest(
remixContext: EntryContext,
) {
return new Promise((resolve, reject) => {
const { pipe, abort } = renderToPipeableStream(
const { abort, pipe } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
Expand All @@ -55,7 +55,7 @@ function handleBotRequest(
responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(createReadableStreamFromReadable(body), {
headers: responseHeaders,
status: responseStatusCode,
}),
Expand Down Expand Up @@ -84,7 +84,7 @@ function handleBrowserRequest(
remixContext: EntryContext,
) {
return new Promise((resolve, reject) => {
const { pipe, abort } = renderToPipeableStream(
const { abort, pipe } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
Expand All @@ -97,7 +97,7 @@ function handleBrowserRequest(
responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(createReadableStreamFromReadable(body), {
headers: responseHeaders,
status: responseStatusCode,
}),
Expand Down
4 changes: 2 additions & 2 deletions app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { cssBundleHref } from "@remix-run/css-bundle";
import type { LinksFunction, LoaderArgs } from "@remix-run/node";
import type { LinksFunction, LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import {
Links,
Expand All @@ -18,7 +18,7 @@ export const links: LinksFunction = () => [
...(cssBundleHref ? [{ rel: "stylesheet", href: cssBundleHref }] : []),
];

export const loader = async ({ request }: LoaderArgs) => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
return json({ user: await getUser(request) });
};

Expand Down
4 changes: 2 additions & 2 deletions app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { V2_MetaFunction } from "@remix-run/node";
import type { MetaFunction } from "@remix-run/node";
import { Link } from "@remix-run/react";

import { useOptionalUser } from "~/utils";

export const meta: V2_MetaFunction = () => [{ title: "Remix Notes" }];
export const meta: MetaFunction = () => [{ title: "Remix Notes" }];

export default function Index() {
const user = useOptionalUser();
Expand Down
4 changes: 2 additions & 2 deletions app/routes/healthcheck.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// learn more: https://fly.io/docs/reference/configuration/#services-http_checks
import type { LoaderArgs } from "@remix-run/node";
import type { LoaderFunctionArgs } from "@remix-run/node";

import { prisma } from "~/db.server";

export const loader = async ({ request }: LoaderArgs) => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
const host =
request.headers.get("X-Forwarded-Host") ?? request.headers.get("host");

Expand Down
12 changes: 8 additions & 4 deletions app/routes/join.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ActionArgs, LoaderArgs, V2_MetaFunction } from "@remix-run/node";
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
MetaFunction,
} from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Form, Link, useActionData, useSearchParams } from "@remix-run/react";
import { useEffect, useRef } from "react";
Expand All @@ -7,13 +11,13 @@ import { createUser, getUserByEmail } from "~/models/user.server";
import { createUserSession, getUserId } from "~/session.server";
import { safeRedirect, validateEmail } from "~/utils";

export const loader = async ({ request }: LoaderArgs) => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
const userId = await getUserId(request);
if (userId) return redirect("/");
return json({});
};

export const action = async ({ request }: ActionArgs) => {
export const action = async ({ request }: ActionFunctionArgs) => {
const formData = await request.formData();
const email = formData.get("email");
const password = formData.get("password");
Expand Down Expand Up @@ -63,7 +67,7 @@ export const action = async ({ request }: ActionArgs) => {
});
};

export const meta: V2_MetaFunction = () => [{ title: "Sign Up" }];
export const meta: MetaFunction = () => [{ title: "Sign Up" }];

export default function Join() {
const [searchParams] = useSearchParams();
Expand Down
12 changes: 8 additions & 4 deletions app/routes/login.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import type { ActionArgs, LoaderArgs, V2_MetaFunction } from "@remix-run/node";
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
MetaFunction,
} from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Form, Link, useActionData, useSearchParams } from "@remix-run/react";
import { useEffect, useRef } from "react";
Expand All @@ -7,13 +11,13 @@ import { verifyLogin } from "~/models/user.server";
import { createUserSession, getUserId } from "~/session.server";
import { safeRedirect, validateEmail } from "~/utils";

export const loader = async ({ request }: LoaderArgs) => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
const userId = await getUserId(request);
if (userId) return redirect("/");
return json({});
};

export const action = async ({ request }: ActionArgs) => {
export const action = async ({ request }: ActionFunctionArgs) => {
const formData = await request.formData();
const email = formData.get("email");
const password = formData.get("password");
Expand Down Expand Up @@ -58,7 +62,7 @@ export const action = async ({ request }: ActionArgs) => {
});
};

export const meta: V2_MetaFunction = () => [{ title: "Login" }];
export const meta: MetaFunction = () => [{ title: "Login" }];

export default function LoginPage() {
const [searchParams] = useSearchParams();
Expand Down
5 changes: 3 additions & 2 deletions app/routes/logout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { ActionArgs } from "@remix-run/node";
import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";

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

export const action = async ({ request }: ActionArgs) => logout(request);
export const action = async ({ request }: ActionFunctionArgs) =>
logout(request);

export const loader = async () => redirect("/");
6 changes: 3 additions & 3 deletions app/routes/notes.$noteId.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ActionArgs, LoaderArgs } from "@remix-run/node";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import {
Form,
Expand All @@ -11,7 +11,7 @@ import invariant from "tiny-invariant";
import { deleteNote, getNote } from "~/models/note.server";
import { requireUserId } from "~/session.server";

export const loader = async ({ params, request }: LoaderArgs) => {
export const loader = async ({ params, request }: LoaderFunctionArgs) => {
const userId = await requireUserId(request);
invariant(params.noteId, "noteId not found");

Expand All @@ -22,7 +22,7 @@ export const loader = async ({ params, request }: LoaderArgs) => {
return json({ note });
};

export const action = async ({ params, request }: ActionArgs) => {
export const action = async ({ params, request }: ActionFunctionArgs) => {
const userId = await requireUserId(request);
invariant(params.noteId, "noteId not found");

Expand Down
4 changes: 2 additions & 2 deletions app/routes/notes.new.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { ActionArgs } from "@remix-run/node";
import type { ActionFunctionArgs } from "@remix-run/node";
import { json, redirect } from "@remix-run/node";
import { Form, useActionData } from "@remix-run/react";
import { useEffect, useRef } from "react";

import { createNote } from "~/models/note.server";
import { requireUserId } from "~/session.server";

export const action = async ({ request }: ActionArgs) => {
export const action = async ({ request }: ActionFunctionArgs) => {
const userId = await requireUserId(request);

const formData = await request.formData();
Expand Down
4 changes: 2 additions & 2 deletions app/routes/notes.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { LoaderArgs } from "@remix-run/node";
import type { LoaderFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { Form, Link, NavLink, Outlet, useLoaderData } from "@remix-run/react";

import { getNoteListItems } from "~/models/note.server";
import { requireUserId } from "~/session.server";
import { useUser } from "~/utils";

export const loader = async ({ request }: LoaderArgs) => {
export const loader = async ({ request }: LoaderFunctionArgs) => {
const userId = await requireUserId(request);
const noteListItems = await getNoteListItems({ userId });
return json({ noteListItems });
Expand Down
2 changes: 1 addition & 1 deletion app/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function useMatchesData(
() => matchingRoutes.find((route) => route.id === id),
[matchingRoutes, id],
);
return route?.data;
return route?.data as Record<string, unknown>;
}

function isUser(user: any): user is User {
Expand Down
4 changes: 2 additions & 2 deletions cypress/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"types": ["node", "cypress", "@testing-library/cypress"],
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"target": "es2019",
"moduleResolution": "Bundler",
"target": "ES2020",
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
"dependencies": {
"@isaacs/express-prometheus-middleware": "^1.2.1",
"@prisma/client": "^4.16.2",
"@remix-run/css-bundle": "*",
"@remix-run/express": "*",
"@remix-run/node": "*",
"@remix-run/react": "*",
"@remix-run/css-bundle": "^2.0.0-pre.12",
"@remix-run/express": "^2.0.0-pre.12",
"@remix-run/node": "^2.0.0-pre.12",
"@remix-run/react": "^2.0.0-pre.12",
"bcryptjs": "^2.4.3",
"chokidar": "^3.5.3",
"compression": "^1.7.4",
Expand All @@ -53,8 +53,8 @@
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@remix-run/dev": "^2.0.0-pre.12",
"@remix-run/eslint-config": "^2.0.0-pre.12",
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.17.0",
"@types/bcryptjs": "^2.4.2",
Expand Down Expand Up @@ -95,7 +95,7 @@
"vitest": "^0.34.2"
},
"engines": {
"node": ">=14.0.0"
"node": ">=18.0.0"
},
"prisma": {
"seed": "ts-node --require tsconfig-paths/register prisma/seed.ts"
Expand Down
12 changes: 1 addition & 11 deletions remix.config.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
cacheDirectory: "./node_modules/.cache/remix",
future: {
v2_dev: true,
v2_errorBoundary: true,
v2_headers: true,
v2_meta: true,
v2_normalizeFormMethod: true,
v2_routeConvention: true,
},
ignoredRouteFiles: ["**/.*", "**/*.test.{js,jsx,ts,tsx}"],
postcss: true,
ignoredRouteFiles: ["**/.*", "**/*.test.{ts,tsx}"],
serverModuleFormat: "cjs",
tailwind: true,
};
Loading

0 comments on commit 7b53ccb

Please sign in to comment.