Skip to content

Commit

Permalink
Use global Request type to prevent type errors (#70)
Browse files Browse the repository at this point in the history
* Remove build.minify: true, add v3_lazyRouteDiscovery

• build: { minify: true } causes variable names to be mangled in the SSR build of the app, which means that Models will have the wrong name and will wind up pointing at non-existent (or wrong) D1 tables
• v3_lazyRouteDiscovery is a new default behavior for remix that doesn’t require any other changes to enable

* 📝 Update remix v1 link, add --remote, grammar

you need to pass the --remote flag to the newest version of wrangler’s migrations apply command in order to get it to run on the production instance of the D1 DB

* 📝 Document vite.config, update worker example

* 📝 Update defunct sessions doc instructions

* 📝 Add handleScheduled to Getting Started doc

* 📝 Mention Vite config gotcha in models doc

* 📝 Update authentication doc for @superflare/remix

* 📝 Update CLI docs with changes to commands

* Replace local docsearch.css → @docsearch/css

also, upgrade from v3.6.1 → v3.8.0 (latest)

* Use global Request type for all request instances

this resolves a type error that was being triggered when using handleFetch<env>(request, …) from a worker.ts script (e.g. in examples/remix-cms). the full TS error:

worker.ts:17:37 - error TS2345: Argument of type 'Request<unknown, IncomingRequestCfProperties<unknown>>' is not assignable to parameter of type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Request<unknown, import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Incomi...'.
  The types of 'clone().headers' are incompatible between these types.
    Property 'getAll' is missing in type 'Headers' but required in type 'import("/Users/andrew/Projects/superflare/node_modules/.pnpm/@cloudflare[email protected]/node_modules/@cloudflare/workers-types/index").Headers'.

17       return await handleFetch<Env>(request, env, ctx, config, handleRequest);
  • Loading branch information
acusti authored Dec 17, 2024
1 parent c47b4f5 commit ae0e7f1
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 19 deletions.
8 changes: 1 addition & 7 deletions packages/superflare-remix/dev.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request,
} from "@cloudflare/workers-types";
import { cloudflareDevProxyVitePlugin } from "@remix-run/dev";
import {
fromNodeRequest,
Expand All @@ -15,8 +11,6 @@ import { type Plugin, type ViteDevServer } from "vite";
import { type GetPlatformProxyOptions } from "wrangler";
import { type Cloudflare, getLoadContext } from "./load-context";

type WorkersRequest = Request<unknown, IncomingRequestCfProperties<unknown>>;

/**
* This is copied from the workers-sdk repo (used for wrangler’s getPlatformProxy).
* Using `waitUntil` means invoking the async function, so a no-op works in dev.
Expand Down Expand Up @@ -76,7 +70,7 @@ export function superflareDevProxyVitePlugin<Env extends { APP_KEY: string }>(
const request = fromNodeRequest(nodeReq, nodeRes);
const loadContext = await getLoadContext<Env>({
context,
request: request as unknown as WorkersRequest,
request,
SuperflareAuth: superflare.SuperflareAuth,
SuperflareSession: superflare.SuperflareSession,
});
Expand Down
6 changes: 1 addition & 5 deletions packages/superflare-remix/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request as WorkersRequest,
} from "@cloudflare/workers-types";
import { type AppLoadContext } from "@remix-run/cloudflare";
import {
type DefineConfigReturn,
Expand All @@ -27,7 +23,7 @@ declare module "@remix-run/cloudflare" {
* It calls getLoadContext to inject `auth` and `session` into the Remix load context.
*/
export async function handleFetch<Env extends { APP_KEY: string }>(
request: WorkersRequest<unknown, IncomingRequestCfProperties<unknown>>,
request: Request,
env: Env,
ctx: ExecutionContext,
config: DefineConfigReturn<any>,
Expand Down
1 change: 0 additions & 1 deletion packages/superflare-remix/load-context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Request } from "@cloudflare/workers-types";
import {
type AppLoadContext,
createCookieSessionStorage,
Expand Down
1 change: 0 additions & 1 deletion packages/superflare/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { type Request } from "@cloudflare/workers-types";
import { sanitizeModuleName } from "./string";

export interface StorageDiskConfig {
Expand Down
6 changes: 1 addition & 5 deletions packages/superflare/src/fetch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import {
type IncomingRequestCfProperties,
type Request,
} from "@cloudflare/workers-types";
import { type DefineConfigReturn } from "./config";
import { type SuperflareSession } from "./session";

Expand All @@ -14,7 +10,7 @@ export async function handleFetch<Env>(
session,
getSessionCookie,
}: {
request: Request<unknown, IncomingRequestCfProperties<unknown>>;
request: Request;
env: Env;
ctx: ExecutionContext;
config: DefineConfigReturn<Env>;
Expand Down

0 comments on commit ae0e7f1

Please sign in to comment.