Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade to Remix v2 #207

Merged
merged 1 commit into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
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