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 6, 2023
1 parent af4c898 commit c1066f7
Show file tree
Hide file tree
Showing 16 changed files with 61 additions and 149 deletions.
7 changes: 3 additions & 4 deletions app/entry.server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* For more information, see https://remix.run/docs/en/main/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";
import { PassThrough, Readable } from "node:stream";

import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";
Expand Down Expand Up @@ -55,7 +54,7 @@ function handleBotRequest(
responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(Readable.toWeb(body) as ReadableStream, {
headers: responseHeaders,
status: responseStatusCode,
}),
Expand Down Expand Up @@ -97,7 +96,7 @@ function handleBrowserRequest(
responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
new Response(Readable.toWeb(body) as ReadableStream, {
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 @@ -20,7 +20,7 @@ export const links: LinksFunction = () => [
{ rel: "icon", href: "/_static/favicon.ico" },
];

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
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
15 changes: 7 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
"@architect/architect": "^10.14.0",
"@architect/functions": "^7.0.0",
"@paralleldrive/cuid2": "^2.2.2",
"@remix-run/architect": "*",
"@remix-run/css-bundle": "*",
"@remix-run/node": "*",
"@remix-run/react": "*",
"@remix-run/server-runtime": "*",
"@remix-run/architect": "^2.0.0-pre.8",
"@remix-run/css-bundle": "^2.0.0-pre.8",
"@remix-run/node": "^2.0.0-pre.8",
"@remix-run/react": "^2.0.0-pre.8",
"bcryptjs": "2.4.3",
"isbot": "^3.6.13",
"react": "^18.2.0",
Expand All @@ -38,8 +37,8 @@
},
"devDependencies": {
"@faker-js/faker": "^8.0.2",
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@remix-run/dev": "^2.0.0-pre.8",
"@remix-run/eslint-config": "^2.0.0-pre.8",
"@testing-library/cypress": "^9.0.0",
"@testing-library/jest-dom": "^5.17.0",
"@types/architect__functions": "^3.13.7",
Expand Down Expand Up @@ -75,6 +74,6 @@
"vitest": "^0.34.2"
},
"engines": {
"node": ">=14"
"node": ">=18.0.0"
}
}
12 changes: 1 addition & 11 deletions remix.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
const path = require("path");
const path = require("node:path");

/** @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}"],
publicPath: "/_static/build/",
postcss: true,
server: "./server.ts",
serverBuildPath: "server/index.js",
serverModuleFormat: "cjs",
tailwind: true,
routes(defineRoutes) {
return defineRoutes((route) => {
if (process.env.NODE_ENV === "production") return;
Expand Down
Loading

0 comments on commit c1066f7

Please sign in to comment.