Skip to content

Commit

Permalink
fix: mark getLoadContext as optional (#461)
Browse files Browse the repository at this point in the history
* fix: mark getLoadContext as optional

Signed-off-by: Logan McAnsh <logan@mcan.sh>

* Create late-lions-flow.md

Signed-off-by: Logan McAnsh <logan@mcan.sh>

* chore: use default export

Signed-off-by: Logan McAnsh <logan@mcan.sh>

---------

Signed-off-by: Logan McAnsh <logan@mcan.sh>
  • Loading branch information
mcansh authored Nov 23, 2024
1 parent 96c83d1 commit a8559e0
Show file tree
Hide file tree
Showing 12 changed files with 184 additions and 334 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-lions-flow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mcansh/remix-fastify": patch
---

fix: mark getLoadContext as optional
2 changes: 1 addition & 1 deletion examples/react-router/app/routes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RouteConfig } from "@react-router/dev/routes";
import { index } from "@react-router/dev/routes";

export const routes: RouteConfig = [index("routes/home.tsx")];
export default [index("routes/home.tsx")] satisfies RouteConfig;
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"attw": "attw ./packages/** --pack",
"lint": "eslint --ignore-path .gitignore --no-error-on-unmatched-pattern --cache --cache-location node_modules/.cache/eslint --fix .",
"format": "prettier --ignore-path .prettierignore --ignore-path .gitignore --ignore-unknown --cache --cache-location node_modules/.cache/prettiercache --write .",
"validate": "run-p lint format publint typecheck",
"validate": "pnpm run --parallel lint format publint typecheck",
"typecheck": "pnpm run --recursive typecheck",
"changeset": "changeset",
"changeset:version": "changeset version && node ./scripts/remove-prerelease-changelogs.js && node ./scripts/post-changeset.js",
Expand All @@ -32,7 +32,6 @@
"eslint-plugin-prefer-let": "^4.0.0",
"glob": "^11.0.0",
"jsonfile": "^6.1.0",
"npm-run-all": "^4.1.5",
"pkg-pr-new": "^0.0.30",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.9",
Expand Down
14 changes: 8 additions & 6 deletions packages/remix-fastify/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { FastifyInstance } from "fastify";

import path from "node:path";
import url from "node:url";
import type { InlineConfig, ViteDevServer } from "vite";
import fastifyStatic, { type FastifyStaticOptions } from "@fastify/static";

import fastifyStatic from "@fastify/static";
import type { FastifyStaticOptions } from "@fastify/static";
import type { FastifyInstance } from "fastify";
import { cacheHeader } from "pretty-cache-header";
import type { GetLoadContextFunction, HttpServer } from "../shared";
import type { InlineConfig, ViteDevServer } from "vite";

import type { CreateRequestHandlerFunction as RRCreateRequestHandlerFunction } from "../servers/react-router";
import type { CreateRequestHandlerFunction as RemixCreateRequestHandlerFunction } from "../servers/remix";
import type { GetLoadContextFunction, HttpServer } from "../shared";

export type PluginOptions<
Server extends HttpServer = HttpServer,
Expand Down Expand Up @@ -39,7 +41,7 @@ export type PluginOptions<
* You can think of this as an escape hatch that allows you to pass
* environment/platform-specific values through to your loader/action.
*/
getLoadContext: GetLoadContextFunction<Server, AppLoadContext>;
getLoadContext?: GetLoadContextFunction<Server, AppLoadContext>;
mode?: string;
/**
* Options to pass to the Vite server in development.
Expand Down
8 changes: 5 additions & 3 deletions packages/remix-fastify/src/plugins/react-router.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import fp from "fastify-plugin";

import type { HttpServer } from "../shared";
import type { AppLoadContext, ServerBuild } from "react-router";

import { createReactRouterRequestHandler } from "../servers/react-router";
import { createPlugin, type PluginOptions } from ".";
import type { HttpServer } from "../shared";

import { createPlugin } from ".";
import type { PluginOptions } from ".";

export type ReactRouterFastifyOptions = Omit<
PluginOptions<HttpServer, AppLoadContext, ServerBuild>,
Expand Down
6 changes: 4 additions & 2 deletions packages/remix-fastify/src/plugins/remix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import fp from "fastify-plugin";
import type { AppLoadContext, ServerBuild } from "@remix-run/node";
import fp from "fastify-plugin";

import { createRemixRequestHandler } from "../servers/remix";
import type { HttpServer } from "../shared";
import { createPlugin, type PluginOptions } from ".";

import { createPlugin } from ".";
import type { PluginOptions } from ".";

export type RemixFastifyOptions = Omit<
PluginOptions<HttpServer, AppLoadContext, ServerBuild>,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-fastify/src/react-router.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppLoadContext } from "react-router";

import type {
HttpServer,
GetLoadContextFunction as SharedGetLoadContextFunction,
Expand Down
1 change: 1 addition & 0 deletions packages/remix-fastify/src/remix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppLoadContext } from "@remix-run/node";

import type {
HttpServer,
GetLoadContextFunction as SharedGetLoadContextFunction,
Expand Down
3 changes: 2 additions & 1 deletion packages/remix-fastify/src/servers/react-router.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { createReadableStreamFromReadable } from "@react-router/node";
import type {
FastifyRequest,
FastifyReply,
RouteGenericInterface,
} from "fastify";
import type { AppLoadContext, ServerBuild } from "react-router";
import { createRequestHandler } from "react-router";
import { createReadableStreamFromReadable } from "@react-router/node";

import { createRequest, sendResponse } from "../shared";
import type {
GetLoadContextFunction as GenericGetLoadContextFunction,
Expand Down
11 changes: 6 additions & 5 deletions packages/remix-fastify/src/servers/remix.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type {
FastifyRequest,
FastifyReply,
RouteGenericInterface,
} from "fastify";
import type { AppLoadContext, ServerBuild } from "@remix-run/node";
import {
createRequestHandler,
createReadableStreamFromReadable,
} from "@remix-run/node";
import type {
FastifyRequest,
FastifyReply,
RouteGenericInterface,
} from "fastify";

import { createRequest, sendResponse } from "../shared";
import type {
GetLoadContextFunction as GenericGetLoadContextFunction,
Expand Down
7 changes: 4 additions & 3 deletions packages/remix-fastify/src/shared.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import { Readable } from "node:stream";
import type * as http from "node:http";
import type * as http2 from "node:http2";
import type * as https from "node:https";
import { Readable } from "node:stream";

import type { createReadableStreamFromReadable as RRCreateReadableStreamFromReadable } from "@react-router/node";
import type { createReadableStreamFromReadable as RemixCreateReadableStreamFromReadable } from "@remix-run/node";
import type {
FastifyReply,
FastifyRequest,
RawReplyDefaultExpression,
RawRequestDefaultExpression,
RouteGenericInterface,
} from "fastify";
import type { createReadableStreamFromReadable as RRCreateReadableStreamFromReadable } from "@react-router/node";
import type { createReadableStreamFromReadable as RemixCreateReadableStreamFromReadable } from "@remix-run/node";

export type HttpServer =
| http.Server
Expand Down
Loading

0 comments on commit a8559e0

Please sign in to comment.