Skip to content

Commit

Permalink
add example with million
Browse files Browse the repository at this point in the history
  • Loading branch information
rphlmr committed Jan 16, 2025
1 parent 0370d40 commit 9c3c1a7
Show file tree
Hide file tree
Showing 26 changed files with 2,980 additions and 123 deletions.
80 changes: 80 additions & 0 deletions examples/node/with-million/.eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* This is intended to be a basic starting point for linting in your app.
* It relies on recommended configs out of the box for simplicity, but you can
* and should modify this configuration to best suit your team's needs.
*/

/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
parserOptions: {
ecmaVersion: "latest",
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
env: {
browser: true,
commonjs: true,
es6: true,
},
ignorePatterns: ["!**/.server", "!**/.client"],

// Base config
extends: ["eslint:recommended"],

overrides: [
// React
{
files: ["**/*.{js,jsx,ts,tsx}"],
plugins: ["react", "jsx-a11y"],
extends: [
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
],
settings: {
react: {
version: "detect",
},
formComponents: ["Form"],
linkComponents: [
{ name: "Link", linkAttribute: "to" },
{ name: "NavLink", linkAttribute: "to" },
],
"import/resolver": {
typescript: {},
},
},
},

// Typescript
{
files: ["**/*.{ts,tsx}"],
plugins: ["@typescript-eslint", "import"],
parser: "@typescript-eslint/parser",
settings: {
"import/internal-regex": "^~/",
"import/resolver": {
node: {
extensions: [".ts", ".tsx"],
},
typescript: {
alwaysTryTypes: true,
},
},
},
extends: ["plugin:@typescript-eslint/recommended", "plugin:import/recommended", "plugin:import/typescript"],
},

// Node
{
files: [".eslintrc.cjs"],
env: {
node: true,
},
},
],
};
5 changes: 5 additions & 0 deletions examples/node/with-million/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules

/.cache
/build
.env
155 changes: 155 additions & 0 deletions examples/node/with-million/.million/store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"encodings": [
"app/entry.server.tsx",
"handleRequest",
[12, 15, 63, 1],
[28, 51, 28, 109],
"app/root.tsx",
"App",
[26, 15, 28, 1],
[27, 9, 27, 19],
"app/routes/app_.sub.tsx",
"Index",
[27, 15, 60, 1],
[27, 30, 27, 72],
[28, 28, 28, 40],
[31, 25, 31, 41],
[31, 10, 31, 20],
[33, 4, 58, 10],
[34, 6, 37, 15],
[34, 37, 34, 47],
[35, 8, 35, 43],
[38, 6, 38, 15],
[39, 6, 39, 72],
[40, 6, 57, 12],
[41, 8, 56, 16],
[42, 10, 47, 18],
[43, 12, 46, 17],
[44, 14, 44, 117],
[45, 14, 45, 119],
[48, 10, 55, 18],
[50, 14, 53, 19],
[51, 16, 51, 104],
[52, 16, 52, 101],
"app/components/input.tsx",
"Input",
[1, 7, 3, 1],
[1, 22, 1, 68],
[2, 9, 2, 61],
"app/routes/_index.tsx"
],
"reactData": {
"app/entry.server.tsx": {
"components": {
"handleRequest": {
"loc": [12, 15, 63, 1],
"nameLoc": [12, 24, 12, 37],
"captures": [{ "loc": [28, 51, 28, 109], "kind": 16 }]
}
},
"externals": [
{ "kind": "import", "loc": [1, 0, 1, 42] },
{ "kind": "import", "loc": [3, 0, 3, 70] },
{ "kind": "import", "loc": [4, 0, 4, 30] },
{ "kind": "import", "loc": [5, 0, 5, 70] },
{ "kind": "import", "loc": [6, 0, 6, 58] },
{ "kind": "import", "loc": [7, 0, 7, 65] },
{ "kind": "import", "loc": [8, 0, 8, 44] },
{ "kind": "export", "loc": [10, 0, 10, 35] },
{ "kind": "export", "loc": [12, 0, 63, 1] }
]
},
"app/root.tsx": {
"components": {
"App": {
"loc": [26, 15, 28, 1],
"nameLoc": [26, 24, 26, 27],
"captures": [{ "loc": [26, 15, 28, 1], "kind": 512 }]
}
},
"externals": [
{ "kind": "import", "loc": [1, 0, 1, 50] },
{ "kind": "import", "loc": [2, 0, 2, 79] },
{ "kind": "import", "loc": [3, 0, 3, 47] },
{ "kind": "export", "loc": [5, 0, 5, 80] },
{ "kind": "export", "loc": [7, 0, 24, 1] },
{ "kind": "export", "loc": [26, 0, 28, 1] }
]
},
"app/routes/app_.sub.tsx": {
"components": {
"Index": {
"loc": [27, 15, 60, 1],
"nameLoc": [27, 24, 27, 29],
"captures": [
{ "loc": [27, 15, 60, 1], "kind": 512 },
{ "loc": [27, 30, 27, 72], "kind": 2 },
{ "loc": [28, 28, 28, 40], "kind": 4 },
{ "loc": [31, 25, 31, 41], "kind": 4 },
{ "loc": [34, 37, 34, 47], "kind": 128 },
{ "loc": [39, 6, 39, 72], "kind": 16 }
]
}
},
"externals": [
{ "kind": "import", "loc": [1, 0, 1, 33] },
{ "kind": "import", "loc": [2, 0, 2, 46] },
{ "kind": "import", "loc": [3, 0, 3, 43] },
{ "kind": "import", "loc": [4, 0, 4, 51] },
{ "kind": "import", "loc": [5, 0, 5, 51] },
{ "kind": "import", "loc": [6, 0, 6, 51] },
{ "kind": "import", "loc": [7, 0, 7, 44] },
{ "kind": "import", "loc": [8, 0, 8, 42] },
{ "kind": "import", "loc": [9, 0, 9, 47] },
{ "kind": "export", "loc": [11, 0, 16, 1] },
{ "kind": "export", "loc": [18, 0, 23, 1] },
{ "kind": "export", "loc": [27, 0, 60, 1] }
]
},
"app/components/input.tsx": {
"components": {
"Input": {
"loc": [1, 7, 3, 1],
"nameLoc": [1, 16, 1, 21],
"captures": [{ "loc": [1, 7, 3, 1], "kind": 512 }, { "loc": [1, 22, 1, 68], "kind": 2 }]
}
},
"externals": [{ "kind": "export", "loc": [1, 0, 3, 1] }]
},
"app/routes/_index.tsx": {
"components": {
"Index": {
"loc": [27, 15, 60, 1],
"nameLoc": [27, 24, 27, 29],
"captures": [
{ "loc": [27, 15, 60, 1], "kind": 512 },
{ "loc": [27, 30, 27, 72], "kind": 2 },
{ "loc": [28, 28, 28, 40], "kind": 4 },
{ "loc": [31, 25, 31, 41], "kind": 4 },
{ "loc": [34, 37, 34, 47], "kind": 128 },
{ "loc": [39, 6, 39, 72], "kind": 16 }
]
}
},
"externals": [
{ "kind": "import", "loc": [1, 0, 1, 33] },
{ "kind": "import", "loc": [2, 0, 2, 46] },
{ "kind": "import", "loc": [3, 0, 3, 43] },
{ "kind": "import", "loc": [4, 0, 4, 51] },
{ "kind": "import", "loc": [5, 0, 5, 51] },
{ "kind": "import", "loc": [6, 0, 6, 51] },
{ "kind": "import", "loc": [7, 0, 7, 44] },
{ "kind": "import", "loc": [8, 0, 8, 42] },
{ "kind": "import", "loc": [9, 0, 9, 45] },
{ "kind": "export", "loc": [11, 0, 16, 1] },
{ "kind": "export", "loc": [18, 0, 23, 1] },
{ "kind": "export", "loc": [27, 0, 60, 1] }
]
}
},
"unusedFiles": [
"/Users/rphlmr/workspaces/rphlmr/react-router-hono-server/examples/node/with-million/app/routes/defer.tsx",
"/Users/rphlmr/workspaces/rphlmr/react-router-hono-server/examples/node/with-million/app/entry.client.tsx"
],
"mtime": null
}
36 changes: 36 additions & 0 deletions examples/node/with-million/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Welcome to Remix + Vite!

📖 See the [Remix docs](https://remix.run/docs) and the [Remix Vite docs](https://remix.run/docs/en/main/guides/vite) for details on supported features.

## Development

Run the Vite dev server:

```shellscript
npm run dev
```

## Deployment

First, build your app for production:

```sh
npm run build
```

Then run the app in production mode:

```sh
npm start
```

Now you'll need to pick a host to deploy it to.

### DIY

If you're familiar with deploying Node applications, the built-in Remix app server is production-ready.

Make sure to deploy the output of `npm run build`

- `build/server`
- `build/client`
3 changes: 3 additions & 0 deletions examples/node/with-million/app/components/input.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function Input(props: React.ComponentPropsWithoutRef<"input">) {
return <input type="text" placeholder="Input" {...props} />;
}
12 changes: 12 additions & 0 deletions examples/node/with-million/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { StrictMode, startTransition } from "react";
import { hydrateRoot } from "react-dom/client";
import { HydratedRouter } from "react-router/dom";

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<HydratedRouter />
</StrictMode>
);
});
63 changes: 63 additions & 0 deletions examples/node/with-million/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { PassThrough } from "node:stream";

import { createReadableStreamFromReadable } from "@react-router/node";
import { isbot } from "isbot";
import type { RenderToPipeableStreamOptions } from "react-dom/server";
import { renderToPipeableStream } from "react-dom/server";
import type { AppLoadContext, EntryContext } from "react-router";
import { ServerRouter } from "react-router";

export const streamTimeout = 5_000;

export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
routerContext: EntryContext,
loadContext: AppLoadContext
) {
return new Promise((resolve, reject) => {
let shellRendered = false;
let userAgent = request.headers.get("user-agent");

// Ensure requests from bots and SPA Mode renders wait for all content to load before responding
// https://react.dev/reference/react-dom/server/renderToPipeableStream#waiting-for-all-content-to-load-for-crawlers-and-static-generation
let readyOption: keyof RenderToPipeableStreamOptions =
(userAgent && isbot(userAgent)) || routerContext.isSpaMode ? "onAllReady" : "onShellReady";

const { pipe, abort } = renderToPipeableStream(<ServerRouter context={routerContext} url={request.url} />, {
[readyOption]() {
shellRendered = true;
const body = new PassThrough();
const stream = createReadableStreamFromReadable(body);

responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(stream, {
headers: responseHeaders,
status: responseStatusCode,
})
);

pipe(body);
},
onShellError(error: unknown) {
reject(error);
},
onError(error: unknown) {
responseStatusCode = 500;
// Log streaming rendering errors from inside the shell. Don't log
// errors encountered during initial shell rendering since they'll
// reject and get logged in handleDocumentRequest.
if (shellRendered) {
console.error(error);
}
},
});

// Abort the rendering stream after the `streamTimeout` so it has tine to
// flush down the rejected boundaries
setTimeout(abort, streamTimeout + 1000);
});
}
28 changes: 28 additions & 0 deletions examples/node/with-million/app/root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import type { LinksFunction } from "react-router";
import { Links, Meta, Outlet, Scripts, ScrollRestoration } from "react-router";
import styles from "~/styles/tailwind.css?url";

export const links: LinksFunction = () => [{ rel: "stylesheet", href: styles }];

export function Layout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<Meta />
<Links />
<link rel="stylesheet" href={styles} />
</head>
<body>
{children}
<ScrollRestoration />
<Scripts />
</body>
</html>
);
}

export default function App() {
return <Outlet />;
}
4 changes: 4 additions & 0 deletions examples/node/with-million/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;
Loading

0 comments on commit 9c3c1a7

Please sign in to comment.