Skip to content

Commit

Permalink
feat(website): upgrade to react router v7
Browse files Browse the repository at this point in the history
  • Loading branch information
IgnisDa committed Jan 29, 2025
1 parent a86ecc3 commit 919ed60
Show file tree
Hide file tree
Showing 21 changed files with 1,050 additions and 99 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.env
.moon/cache
.moon/docker
.react-router
.next/
.pnp.*
Thumbs.db
Expand Down
2 changes: 1 addition & 1 deletion apps/website/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ COPY --from=website-builder --chown=ryot:ryot /app/apps/website/node_modules ./n
COPY --from=website-builder --chown=ryot:ryot /app/apps/website/package.json ./package.json
COPY --from=website-builder --chown=ryot:ryot /app/apps/website/build ./build
COPY --chown=ryot:ryot apps/website/app/drizzle/migrations app/drizzle/migrations
CMD npx remix-serve ./build/server/index.js
CMD npx react-router-serve ./build/server/index.js
4 changes: 2 additions & 2 deletions apps/website/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RemixBrowser } from "@remix-run/react";
import { StrictMode, startTransition } from "react";
import { hydrateRoot } from "react-dom/client";
import { HydratedRouter } from "react-router/dom";

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
<HydratedRouter />
</StrictMode>,
);
});
28 changes: 10 additions & 18 deletions apps/website/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { PassThrough } from "node:stream";
import type { AppLoadContext, EntryContext } from "@remix-run/node";
import { createReadableStreamFromReadable } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import { createReadableStreamFromReadable } from "@react-router/node";
import { migrate } from "drizzle-orm/postgres-js/migrator";
import { isbot } from "isbot";
import { renderToPipeableStream } from "react-dom/server";
import type { AppLoadContext, EntryContext } from "react-router";
import { ServerRouter } from "react-router";
import { db } from "./lib/config.server";

migrate(db, { migrationsFolder: "app/drizzle/migrations" }).catch((error) => {
Expand All @@ -18,38 +18,34 @@ export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
reactRouterContext: EntryContext,
_loadContext: AppLoadContext,
) {
return isbot(request.headers.get("user-agent") || "")
? handleBotRequest(
request,
responseStatusCode,
responseHeaders,
remixContext,
reactRouterContext,
)
: handleBrowserRequest(
request,
responseStatusCode,
responseHeaders,
remixContext,
reactRouterContext,
);
}

function handleBotRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
reactRouterContext: EntryContext,
) {
return new Promise((resolve, reject) => {
let shellRendered = false;
const { pipe, abort } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
/>,
<ServerRouter context={reactRouterContext} url={request.url} />,
{
onAllReady() {
shellRendered = true;
Expand Down Expand Up @@ -88,16 +84,12 @@ function handleBrowserRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext,
reactRouterContext: EntryContext,
) {
return new Promise((resolve, reject) => {
let shellRendered = false;
const { pipe, abort } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
/>,
<ServerRouter context={reactRouterContext} url={request.url} />,
{
onShellReady() {
shellRendered = true;
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/lib/components/Pricing.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Link } from "@remix-run/react";
import { changeCase } from "@ryot/ts-utils";
import { IconPlayerPlay } from "@tabler/icons-react";
import { useState } from "react";
import { Link } from "react-router";
import { $path } from "remix-routes";
import type { TPrices } from "../config.server";
import { Button } from "./ui/button";
Expand Down
2 changes: 1 addition & 1 deletion apps/website/app/lib/config.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Environment, Paddle } from "@paddle/paddle-node-sdk";
import { render } from "@react-email/render";
import { createCookie } from "@remix-run/node";
import { formatDateToNaiveDate, zodBoolAsString } from "@ryot/ts-utils";
import { Unkey } from "@unkey/api";
import type { Dayjs } from "dayjs";
Expand All @@ -9,6 +8,7 @@ import { drizzle } from "drizzle-orm/postgres-js";
import { GraphQLClient } from "graphql-request";
import { createTransport } from "nodemailer";
import { Issuer } from "openid-client";
import { createCookie } from "react-router";
import { Honeypot } from "remix-utils/honeypot/server";
import { z } from "zod";
import * as schema from "~/drizzle/schema.server";
Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import {
isRouteErrorResponse,
useLoaderData,
useRouteError,
} from "@remix-run/react";
} from "react-router";
import { HoneypotProvider } from "remix-utils/honeypot/react";
import "./tailwind.css";
import type {
LinksFunction,
LoaderFunctionArgs,
MetaFunction,
} from "@remix-run/node";
} from "react-router";
import { $path } from "remix-routes";
import { withFragment } from "ufo";
import { Toaster } from "./lib/components/ui/sonner";
Expand Down
4 changes: 4 additions & 0 deletions apps/website/app/routes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { RouteConfig } from "@react-router/dev/routes";
import { flatRoutes } from "@react-router/fs-routes";

export default flatRoutes() satisfies RouteConfig;
19 changes: 5 additions & 14 deletions apps/website/app/routes/_index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { randomBytes } from "node:crypto";
import TTLCache from "@isaacs/ttlcache";
import {
type ActionFunctionArgs,
type LoaderFunctionArgs,
data,
redirect,
} from "@remix-run/node";
import {
Form,
Link,
useLoaderData,
useRouteLoaderData,
} from "@remix-run/react";
import LoginCodeEmail from "@ryot/transactional/emails/LoginCode";
import {
cn,
Expand All @@ -29,6 +17,8 @@ import {
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import { REGEXP_ONLY_DIGITS } from "input-otp";
import { data, redirect } from "react-router";
import { Form, Link, useLoaderData, useRouteLoaderData } from "react-router";
import { $path } from "remix-routes";
import { HoneypotInputs } from "remix-utils/honeypot/react";
import { SpamError } from "remix-utils/honeypot/server";
Expand All @@ -55,6 +45,7 @@ import {
} from "~/lib/config.server";
import { startUrl } from "~/lib/utils";
import type { loader as rootLoader } from "../root";
import type { Route } from "./+types/_index";

dayjs.extend(duration);

Expand All @@ -65,7 +56,7 @@ const searchParamsSchema = z.object({

export type SearchParams = z.infer<typeof searchParamsSchema>;

export const loader = async ({ request }: LoaderFunctionArgs) => {
export const loader = async ({ request }: Route.LoaderArgs) => {
const query = parseSearchQuery(request, searchParamsSchema);
return { prices, query };
};
Expand All @@ -82,7 +73,7 @@ const generateOtp = (length: number) => {
return otp.toString().padStart(length, "0");
};

export const action = async ({ request }: ActionFunctionArgs) => {
export const action = async ({ request }: Route.ActionArgs) => {
const formData = await request.clone().formData();
const intent = getActionIntent(request);
return await match(intent)
Expand Down
5 changes: 3 additions & 2 deletions apps/website/app/routes/callback.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type LoaderFunctionArgs, redirect } from "@remix-run/node";
import { eq } from "drizzle-orm";
import { redirect } from "react-router";
import { $path } from "remix-routes";
import { match } from "ts-pattern";
import { customers } from "~/drizzle/schema.server";
Expand All @@ -9,8 +9,9 @@ import {
oauthClient,
websiteAuthCookie,
} from "~/lib/config.server";
import type { Route } from "./+types/callback";

export const loader = async ({ request }: LoaderFunctionArgs) => {
export const loader = async ({ request }: Route.LoaderArgs) => {
const client = await oauthClient();
const params = client.callbackParams(request.url);
const tokenSet = await client.callback(OAUTH_CALLBACK_URL, params, {
Expand Down
5 changes: 3 additions & 2 deletions apps/website/app/routes/features.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { LoaderFunctionArgs, MetaArgs } from "@remix-run/node";
import { cn, snakeCase } from "@ryot/ts-utils";
import Autoplay from "embla-carousel-autoplay";
import {
Expand Down Expand Up @@ -34,14 +33,16 @@ import {
LucideVibrate,
LucideWatch,
} from "lucide-react";
import type { MetaArgs } from "react-router";
import {
Carousel,
CarouselContent,
CarouselItem,
} from "~/lib/components/ui/carousel";
import { logoUrl } from "~/lib/utils";
import type { Route } from "./+types/features";

export const loader = (_args: LoaderFunctionArgs) => {
export const loader = (_args: Route.LoaderArgs) => {
return {};
};

Expand Down
13 changes: 5 additions & 8 deletions apps/website/app/routes/me.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ import {
type Paddle,
initializePaddle,
} from "@paddle/paddle-js";
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
MetaArgs,
} from "@remix-run/node";
import { Form, redirect, useLoaderData } from "@remix-run/react";
import PurchaseCompleteEmail from "@ryot/transactional/emails/PurchaseComplete";
import {
changeCase,
Expand All @@ -19,6 +13,8 @@ import { Unkey } from "@unkey/api";
import dayjs from "dayjs";
import { eq } from "drizzle-orm";
import { useEffect, useState } from "react";
import type { MetaArgs } from "react-router";
import { Form, redirect, useLoaderData } from "react-router";
import { toast } from "sonner";
import { match } from "ts-pattern";
import { withQuery } from "ufo";
Expand All @@ -38,8 +34,9 @@ import {
websiteAuthCookie,
} from "~/lib/config.server";
import { startUrl } from "~/lib/utils";
import type { Route } from "./+types/me";

export const loader = async ({ request }: LoaderFunctionArgs) => {
export const loader = async ({ request }: Route.LoaderArgs) => {
const customerDetails = await getCustomerFromCookie(request);
if (!customerDetails) return redirect(startUrl);
return {
Expand All @@ -54,7 +51,7 @@ export const meta = (_args: MetaArgs<typeof loader>) => {
return [{ title: "My account | Ryot" }];
};

export const action = async ({ request }: ActionFunctionArgs) => {
export const action = async ({ request }: Route.ActionArgs) => {
const intent = getActionIntent(request);
return await match(intent)
.with("regenerateUnkeyKey", async () => {
Expand Down
4 changes: 2 additions & 2 deletions apps/website/app/routes/paddle-webhook.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { EventName } from "@paddle/paddle-node-sdk";
import type { ActionFunctionArgs } from "@remix-run/node";
import {
RegisterUserDocument,
UpdateUserDocument,
Expand All @@ -23,6 +22,7 @@ import {
serverGqlService,
serverVariables,
} from "~/lib/config.server";
import type { Route } from "./+types/paddle-webhook";

const getRenewOnFromPlanType = (planType: TPlanTypes) =>
match(planType)
Expand All @@ -31,7 +31,7 @@ const getRenewOnFromPlanType = (planType: TPlanTypes) =>
.with("monthly", () => dayjs().add(1, "month"))
.exhaustive();

export const action = async ({ request }: ActionFunctionArgs) => {
export const action = async ({ request }: Route.ActionArgs) => {
const paddleSignature = request.headers.get("paddle-signature");
if (!paddleSignature) return Response.json({ error: "No paddle signature" });

Expand Down
5 changes: 3 additions & 2 deletions apps/website/app/routes/terms.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import type { LoaderFunctionArgs, MetaArgs } from "@remix-run/node";
import type { MetaArgs } from "react-router";
import type { Route } from "./+types/terms";

const email = "[email protected]";

export const loader = (_args: LoaderFunctionArgs) => {
export const loader = (_args: Route.LoaderArgs) => {
return {};
};

Expand Down
2 changes: 0 additions & 2 deletions apps/website/env.d.ts

This file was deleted.

12 changes: 6 additions & 6 deletions apps/website/moon.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
dependsOn:
- 'assets'
- "assets"

tasks:
dev:
command: 'remix vite:dev --port 5200 --host'
command: "react-router dev --port 5200 --host"
local: true

build:
command: 'remix vite:build'
inputs: ['@group(remix)']
outputs: ['build']
command: "react-router build"
inputs: ["@group(remix)"]
outputs: ["build"]

typecheck:
inputs: ['@group(remix)']
inputs: ["@group(remix)"]
11 changes: 6 additions & 5 deletions apps/website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"@radix-ui/react-slot": "1.1.1",
"@radix-ui/react-tooltip": "1.1.7",
"@react-email/components": "0.0.32",
"@remix-run/node": "2.15.2",
"@remix-run/react": "2.15.2",
"@remix-run/serve": "2.15.2",
"@react-router/fs-routes": "7.1.3",
"@react-router/node": "^7.0.0",
"@react-router/serve": "^7.0.0",
"@ryot/generated": "workspace:*",
"@ryot/graphql": "workspace:*",
"@ryot/transactional": "workspace:*",
Expand Down Expand Up @@ -46,6 +46,7 @@
"postgres": "3.4.5",
"react": "18.3.1",
"react-dom": "18.3.1",
"react-router": "^7.0.0",
"remix-routes": "1.7.7",
"remix-utils": "7.7.0",
"sonner": "1.7.2",
Expand All @@ -57,7 +58,7 @@
"zod": "3.24.1"
},
"devDependencies": {
"@remix-run/dev": "2.15.2",
"@react-router/dev": "^7.0.0",
"@tailwindcss/typography": "0.5.16",
"@types/crypto-js": "4.2.2",
"@types/lodash": "4.17.14",
Expand All @@ -69,7 +70,7 @@
"tailwindcss": "4.0.0",
"typescript": "5.7.3",
"typescript-remix-routes-plugin": "1.0.1",
"vite": "5.4.14",
"vite": "6.0.11",
"vite-tsconfig-paths": "5.1.4"
},
"engines": {
Expand Down
5 changes: 5 additions & 0 deletions apps/website/react-router.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Config } from "@react-router/dev/config";

export default {
ssr: true,
} satisfies Config;
Loading

0 comments on commit 919ed60

Please sign in to comment.