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: add react router entry point #459

Merged
merged 13 commits into from
Nov 20, 2024
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
5 changes: 5 additions & 0 deletions .changeset/spicy-donuts-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mcansh/remix-fastify": patch
---

feat: add react router entry point
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ yalc.lock
# added during build
/packages/*/LICENSE
.tsup
.idea
1 change: 1 addition & 0 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"devDependencies": {
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@total-typescript/tsconfig": "^1.0.4",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"chokidar": "^4.0.1",
Expand Down
12 changes: 2 additions & 10 deletions examples/basic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
{
"include": ["remix.env.d.ts", "**/*.ts", "**/*.tsx"],
"extends": "@total-typescript/tsconfig/bundler/dom/app",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"types": ["@remix-run/node"],
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
9 changes: 5 additions & 4 deletions examples/playground/app/root.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { json } from "@remix-run/node";
import { data } from "@remix-run/node";
import {
Links,
Meta,
Expand All @@ -10,11 +10,12 @@ import {
import "./styles/global.css";

export function loader() {
return json({ message: "Hello from the root loader" });
return data({ message: "Hello from the root loader" });
}

export default function App() {
let data = useLoaderData<typeof loader>();
let loaderData = useLoaderData<typeof loader>();

return (
<html lang="en">
<head>
Expand All @@ -28,7 +29,7 @@ export default function App() {
</head>
<body>
<div className="mx-auto max-w-max border-2 border-black bg-red-700 p-4 text-white">
{data.message}
{loaderData.message}
</div>
<Outlet />
<Scripts />
Expand Down
20 changes: 10 additions & 10 deletions examples/playground/app/routes/_layout._index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from "react";
import type { DataFunctionArgs } from "@remix-run/node";
import { defer, redirect } from "@remix-run/node";
import type { ActionFunctionArgs, LoaderFunctionArgs } from "@remix-run/node";
import { redirect } from "@remix-run/node";
import { Await, Form, useAsyncValue, useLoaderData } from "@remix-run/react";

import { sessionStorage } from "~/session.server";
import { sleep } from "~/sleep";

export async function loader({ request, context }: DataFunctionArgs) {
export async function loader({ request, context }: LoaderFunctionArgs) {
let cookie = request.headers.get("Cookie");
let session = await sessionStorage.getSession(cookie);

Expand All @@ -16,13 +16,13 @@ export async function loader({ request, context }: DataFunctionArgs) {
throw new Error("loadContextName must be a string");
}

return defer({
return {
name: sleep<string>(1_000, session.get("name") || "Anonymous"),
loadContextName,
});
};
}

export async function action({ request }: DataFunctionArgs) {
export async function action({ request }: ActionFunctionArgs) {
let cookie = request.headers.get("Cookie");
let session = await sessionStorage.getSession(cookie);
let formData = await request.formData();
Expand Down Expand Up @@ -55,24 +55,24 @@ export async function action({ request }: DataFunctionArgs) {
}

export default function Index() {
let data = useLoaderData<typeof loader>();
let loaderData = useLoaderData<typeof loader>();
const [echo, setEcho] = React.useState<string | null>(null);

return (
<>
<React.Suspense fallback={<h2 className="text-gray-400">loading...</h2>}>
<Await resolve={data.name} errorElement={<h2>failed...</h2>}>
<Await resolve={loaderData.name} errorElement={<h2>failed...</h2>}>
{(resolvedName) => <h2>Hello {resolvedName}</h2>}
</Await>
</React.Suspense>

<h2>Context: {data.loadContextName}</h2>
<h2>Context: {loaderData.loadContextName}</h2>

<Form method="post" className="flex justify-center gap-2">
<label>
<span>Name: </span>
<React.Suspense fallback={<FallbackNameInput />}>
<Await resolve={data.name}>
<Await resolve={loaderData.name}>
<NameInput />
</Await>
</React.Suspense>
Expand Down
11 changes: 5 additions & 6 deletions examples/playground/app/routes/_layout.fetcher.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { DataFunctionArgs } from "@remix-run/node";
import { json } from "@remix-run/node";
import { useFetcher } from "@remix-run/react";
import type { ActionFunctionArgs } from "@remix-run/node";
import { data, useFetcher } from "@remix-run/react";

export async function action({ request }: DataFunctionArgs) {
let data = await request.json();
return json(data);
export async function action({ request }: ActionFunctionArgs) {
let response = await request.json();
return data(response);
}

export default function () {
Expand Down
6 changes: 3 additions & 3 deletions examples/playground/app/routes/_layout.page-2.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as React from "react";
import { defer } from "@remix-run/node";

import { Await, useLoaderData } from "@remix-run/react";

import { withDelay } from "~/sleep";

export function loader() {
return defer({
return {
message: "loader data from page 2",
deferred: withDelay(2_000, "some text\n".repeat(2_000)),
});
};
}

export default function Page2() {
Expand Down
23 changes: 12 additions & 11 deletions examples/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@
"dependencies": {
"@fastify/static": "^8.0.2",
"@mcansh/remix-fastify": "workspace:*",
"@remix-run/node": "*",
"@remix-run/react": "*",
"@remix-run/node": "^2.14.0",
"@remix-run/react": "^2.14.0",
"chalk": "^5.3.0",
"fastify": "^5.0.0",
"fastify": "^5.1.0",
"get-port": "^7.1.0",
"isbot": "^5.1.17",
"react": "19.0.0-rc-100dfd7dab-20240701",
"react-dom": "19.0.0-rc-100dfd7dab-20240701",
"react": "19.0.0-rc.1",
"react-dom": "19.0.0-rc.1",
"source-map-support": "^0.5.21"
},
"devDependencies": {
"@fastify/middie": "^9.0.2",
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@tailwindcss/vite": "4.0.0-alpha.28",
"@remix-run/dev": "^2.14.0",
"@remix-run/eslint-config": "^2.14.0",
"@tailwindcss/vite": "4.0.0-alpha.34",
"@total-typescript/tsconfig": "^1.0.4",
"@types/react": "npm:types-react@19.0.0-rc.1",
"@types/react-dom": "npm:types-react-dom@19.0.0-rc.1",
"chokidar": "^4.0.1",
Expand All @@ -41,10 +42,10 @@
"npm-run-all": "^4.1.5",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.8",
"tailwindcss": "4.0.0-alpha.28",
"tailwindcss": "4.0.0-alpha.34",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vite-tsconfig-paths": "^5.0.1"
"vite": "^5.4.11",
"vite-tsconfig-paths": "^5.1.2"
},
"overrides": {
"@types/react": "$@types/react",
Expand Down
4 changes: 2 additions & 2 deletions examples/playground/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk";
import { remixFastify } from "@mcansh/remix-fastify";
import { reactRouterFastify } from "@mcansh/remix-fastify/react-router";
import { installGlobals } from "@remix-run/node";
import { fastify } from "fastify";
import sourceMapSupport from "source-map-support";
Expand All @@ -14,7 +14,7 @@ app.post("/api/echo", async (request, reply) => {
reply.send(request.body);
});

await app.register(remixFastify, {
await app.register(reactRouterFastify, {
getLoadContext(request, reply) {
return { loadContextName: "Logan" };
},
Expand Down
15 changes: 3 additions & 12 deletions examples/playground/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,22 @@
{
"extends": "@total-typescript/tsconfig/bundler/dom/app",
"include": [
"**/*.ts",
"**/*.tsx",
"**/.server/**/*.ts",
"**/.server/**/*.tsx",
"**/.client/**/*.ts",
"**/.client/**/*.tsx"
"**/.client/**/*.tsx",
".react-router/types/**/*"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/node", "vite/client"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
21 changes: 20 additions & 1 deletion examples/playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";
import tailwindcss from "@tailwindcss/vite";

declare module "@remix-run/node" {
interface Future {
v3_singleFetch: true;
}
}

export default defineConfig({
plugins: [remix(), tsconfigPaths(), tailwindcss()],
plugins: [
remix({
future: {
unstable_optimizeDeps: true,
v3_fetcherPersist: true,
v3_lazyRouteDiscovery: true,
v3_relativeSplatPath: true,
v3_singleFetch: true,
v3_throwAbortReason: true,
},
}),
tsconfigPaths(),
tailwindcss(),
],
});
2 changes: 2 additions & 0 deletions examples/react-router/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "react-router-example-template",
"private": true,
"sideEffects": false,
"type": "module",
Expand All @@ -24,6 +25,7 @@
},
"devDependencies": {
"@react-router/dev": "7.0.0-pre.4",
"@total-typescript/tsconfig": "^1.0.4",
"@types/react": "^18.3.9",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
Expand Down
6 changes: 2 additions & 4 deletions examples/react-router/server.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from "chalk";
import { remixFastify } from "@mcansh/remix-fastify";
import { reactRouterFastify } from "@mcansh/remix-fastify/react-router";
import { fastify } from "fastify";
import sourceMapSupport from "source-map-support";
import getPort, { portNumbers } from "get-port";
Expand All @@ -8,9 +8,7 @@ sourceMapSupport.install();

let app = fastify();

await app.register(remixFastify, {
virtualModule: "virtual:react-router/server-build",
});
await app.register(reactRouterFastify);

const desiredPort = Number(process.env.PORT) || 3000;
const portToUse = await getPort({
Expand Down
11 changes: 1 addition & 10 deletions examples/react-router/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "@total-typescript/tsconfig/bundler/dom/app",
"include": [
"**/*.ts",
"**/*.tsx",
Expand All @@ -9,18 +10,8 @@
".react-router/types/**/*"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@react-router/node", "vite/client"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"module": "ESNext",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022",
"strict": true,
"allowJs": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
Expand Down
1 change: 1 addition & 0 deletions examples/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"devDependencies": {
"@remix-run/dev": "*",
"@remix-run/eslint-config": "*",
"@total-typescript/tsconfig": "^1.0.4",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
"@types/source-map-support": "^0.5.10",
Expand Down
14 changes: 1 addition & 13 deletions examples/vite/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"extends": "@total-typescript/tsconfig/bundler/dom/app",
"include": [
"**/*.ts",
"**/*.tsx",
Expand All @@ -8,26 +9,13 @@
"**/.client/**/*.tsx"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"types": ["@remix-run/node", "vite/client"],
"isolatedModules": true,
"esModuleInterop": true,
"module": "ESNext",
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"moduleDetection": "force",
"resolveJsonModule": true,
"target": "ES2022",
"skipLibCheck": true,
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},

// Remix takes care of building everything in `remix build`.
"noEmit": true
}
}
Loading