Skip to content

Commit

Permalink
feat: upgrade to Remix v2 (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Sep 15, 2023
1 parent 6bed4af commit f696807
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 144 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
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/support/test-routes/create-user.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { ActionArgs } from "@remix-run/node";
import type { ActionFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";

import { createUser } from "~/models/user.server";
import { createUserSession } from "~/session.server";

export const action = async ({ request }: ActionArgs) => {
export const action = async ({ request }: ActionFunctionArgs) => {
if (process.env.NODE_ENV === "production") {
console.error(
"🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨 test routes should not be enabled in production 🚨 🚨 🚨 🚨 🚨 🚨 🚨 🚨",
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
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@remix-run/css-bundle": "*",
"@remix-run/node": "*",
"@remix-run/react": "*",
"@remix-run/server-runtime": "*",
"bcryptjs": "2.4.3",
"isbot": "^3.6.13",
"react": "^18.2.0",
Expand Down Expand Up @@ -77,6 +76,6 @@
"vitest": "^0.34.2"
},
"engines": {
"node": ">=14.0.0"
"node": ">=18.0.0"
}
}
10 changes: 0 additions & 10 deletions remix.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,11 @@ import path from "node:path";
/** @type {import('@remix-run/dev').AppConfig} */
export default {
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}"],
publicPath: "/_static/build/",
postcss: true,
server: "server.ts",
serverBuildPath: "server/index.mjs",
serverModuleFormat: "esm",
tailwind: true,
routes: (defineRoutes) =>
defineRoutes((route) => {
if (process.env.NODE_ENV === "production") return;
Expand Down
Loading

0 comments on commit f696807

Please sign in to comment.