Skip to content

Commit

Permalink
feat: upgrade to Remix v2 (#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed Sep 15, 2023
1 parent 376beeb commit 6453ae0
Show file tree
Hide file tree
Showing 17 changed files with 66 additions and 150 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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"scripts": {
"build": "remix build",
"dev": "remix dev -c \"npm run dev:serve\"",
"dev:serve": "binode --require ./mocks -- @remix-run/serve:remix-serve ./build",
"dev:serve": "binode --require ./mocks -- @remix-run/serve:remix-serve ./build/index.js",
"format": "prettier --write .",
"format:repo": "npm run format && npm run lint:repo -- --fix",
"lint": "eslint --cache --cache-location ./node_modules/.cache/eslint .",
"lint:repo": "npm run lint -- --config .eslintrc.repo.js",
"setup": "prisma generate && prisma migrate deploy && prisma db seed",
"start": "remix-serve build",
"start:mocks": "binode --require ./mocks -- @remix-run/serve:remix-serve build",
"start": "remix-serve ./build/index.js",
"start:mocks": "binode --require ./mocks -- @remix-run/serve:remix-serve ./build/index.js",
"test": "vitest",
"test:e2e:dev": "start-server-and-test dev http://localhost:3000 \"npx cypress open\"",
"pretest:e2e:run": "npm run build",
Expand Down Expand Up @@ -78,7 +78,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 6453ae0

Please sign in to comment.