Repository: remix-run/remix
Pull request #2542 (2022-03-29 17:29:50)

feat(remix-cloudflare): rename `createCloudflareKVSessionStorage` to `createWorkersKVSessionStorage`
Rename to `createWorkersKVSessionStorage` for consistency with the "Workers KV" product name.

MichaelDeBoey: @mjackson It seems like we have some conflicts to resolve here
changeset-bot[bot]: ###  ⚠️  No Changeset found

Latest commit: 64f490c3a86e150227c62342e79f708be66cc8e9

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. **If these changes should result in a version bump, you need to add a changeset.**

<details><summary>This PR includes no changesets</summary>

  When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

</details>

[Click here to learn what changesets are, and how to add one](https://github.com/changesets/changesets/blob/master/docs/adding-a-changeset.md).

[Click here if you're a maintainer who wants to add a changeset to this PR](https://github.com/remix-run/remix/new/michael/rem-926-rename-createcloudflarekvsessionstorage?filename=.changeset/smart-ghosts-poke.md&value=---%0A%22remix%22%3A%20patch%0A%22%40remix-run%2Fcloudflare%22%3A%20patch%0A---%0A%0Achore(remix-cloudflare%2Cremix-cloudflare-pages%2Cremix-cloudflare-workers)%3A%20rename%20%60createCloudflareKVSessionStorage%60%20to%20%60createWorkersKVSessionStorage%60%0A)


MichaelDeBoey: @mjackson I took the liberty of resolving all conversations here, so we can get this one merged
MichaelDeBoey: @mcansh @pcattori Anything that's preventing us from merging this one?
MichaelDeBoey: @mcansh @pcattori Anything that's preventing us from merging this one?

Patch:
diff --git a/.changeset/breezy-dancers-lie.md b/.changeset/breezy-dancers-lie.md
new file mode 100644
index 000000000..a836b0932
--- /dev/null
+++ b/.changeset/breezy-dancers-lie.md
@@ -0,0 +1,5 @@
+---
+"@remix-run/cloudflare": minor
+---
+
+Rename `createCloudflareKVSessionStorage` to `createWorkersKVSessionStorage`
diff --git a/.changeset/short-bobcats-switch.md b/.changeset/short-bobcats-switch.md
new file mode 100644
index 000000000..b5d82a9cf
--- /dev/null
+++ b/.changeset/short-bobcats-switch.md
@@ -0,0 +1,5 @@
+---
+"@remix-run/server-runtime": minor
+---
+
+remove `react` & `react-dom` from `peerDependencies`
diff --git a/docs/api/remix.md b/docs/api/remix.md
index 880d960f5..c4eb41b4b 100644
--- a/docs/api/remix.md
+++ b/docs/api/remix.md
@@ -258,7 +258,7 @@ title: Remix Packages
 
 [Moved →][moved-59]
 
-### `createCloudflareKVSessionStorage` (cloudflare-workers)
+### `createWorkersKVSessionStorage` (Cloudflare Workers)
 
 [Moved →][moved-60]
 
@@ -354,7 +354,7 @@ title: Remix Packages
 [moved-57]: ../utils/sessions#createcookiesessionstorage
 [moved-58]: ../utils/sessions#creatememorysessionstorage
 [moved-59]: ../utils/sessions#createfilesessionstorage-node
-[moved-60]: ../utils/sessions#createcloudflarekvsessionstorage-cloudflare-workers
+[moved-60]: ../utils/sessions#createworkerskvsessionstorage-cloudflare-workers
 [moved-61]: ../utils/sessions#createarctablesessionstorage-architect-amazon-dynamodb
 [moved-62]: ../utils/sessions#session-api
 [moved-63]: ../utils/sessions#sessionhaskey
diff --git a/docs/utils/sessions.md b/docs/utils/sessions.md
index ac5beef9c..af56f4f9e 100644
--- a/docs/utils/sessions.md
+++ b/docs/utils/sessions.md
@@ -13,7 +13,7 @@ Remix comes with several pre-built session storage options for common scenarios,
 - `createCookieSessionStorage`
 - `createMemorySessionStorage`
 - `createFileSessionStorage` (node)
-- `createCloudflareKVSessionStorage` (cloudflare-workers)
+- `createWorkersKVSessionStorage` (Cloudflare Workers)
 - `createArcTableSessionStorage` (architect, Amazon DynamoDB)
 - custom storage with `createSessionStorage`
 
@@ -330,16 +330,16 @@ const { getSession, commitSession, destroySession } =
 export { getSession, commitSession, destroySession };
 ```
 
-## `createCloudflareKVSessionStorage` (cloudflare-workers)
+## `createWorkersKVSessionStorage` (Cloudflare Workers)
 
-For [Cloudflare KV][cloudflare-kv] backed sessions, use `createCloudflareKVSessionStorage()`.
+For [Cloudflare Workers KV][cloudflare-kv] backed sessions, use `createWorkersKVSessionStorage()`.
 
 The advantage of KV backed sessions is that only the session ID is stored in the cookie while the rest of the data is stored in a globally replicated, low-latency data store with exceptionally high read volumes with low-latency.
 
 ```js filename=app/sessions.server.js
 import {
   createCookie,
-  createCloudflareKVSessionStorage,
+  createWorkersKVSessionStorage,
 } from "@remix-run/cloudflare";
 
 // In this example the Cookie is created separately.
@@ -349,7 +349,7 @@ const sessionCookie = createCookie("__session", {
 });
 
 const { getSession, commitSession, destroySession } =
-  createCloudflareKVSessionStorage({
+  createWorkersKVSessionStorage({
     // The KV Namespace where you want to store sessions
     kv: YOUR_NAMESPACE,
     cookie: sessionCookie,
diff --git a/packages/remix-cloudflare/index.ts b/packages/remix-cloudflare/index.ts
index 9f00786cc..a97982e41 100644
--- a/packages/remix-cloudflare/index.ts
+++ b/packages/remix-cloudflare/index.ts
@@ -1,6 +1,22 @@
 import "./globals";
 
-export { createCloudflareKVSessionStorage } from "./sessions/cloudflareKVSessionStorage";
+import {createWorkersKVSessionStorage} from './sessions/workersKVStorage';
+
+const warn = <T extends Function>(fn: T, message: string): T =>
+  ((...args: unknown[]) => {
+    console.warn(message);
+
+    return fn(...args);
+  }) as unknown as T;
+
+
+/** @deprecated Use `createWorkersKVSessionStorage` instead. */
+export const createCloudflareKVSessionStorage = warn(
+  createWorkersKVSessionStorage,
+  "`createCloudflareKVSessionStorage` is deprecated. Please use `createWorkersKVSessionStorage` instead.",
+);
+
+export { createWorkersKVSessionStorage } from "./sessions/workersKVStorage";
 
 export {
   createCookie,
diff --git a/packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts b/packages/remix-cloudflare/sessions/workersKVStorage.ts
similarity index 92%
rename from packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts
rename to packages/remix-cloudflare/sessions/workersKVStorage.ts
index 455c74e39..45a4573b4 100644
--- a/packages/remix-cloudflare/sessions/cloudflareKVSessionStorage.ts
+++ b/packages/remix-cloudflare/sessions/workersKVStorage.ts
@@ -5,7 +5,7 @@ import type {
 
 import { createSessionStorage } from "../implementations";
 
-interface CloudflareKVSessionStorageOptions {
+interface WorkersKVSessionStorageOptions {
   /**
    * The Cookie used to store the session id on the client, or options used
    * to automatically create one.
@@ -24,10 +24,10 @@ interface CloudflareKVSessionStorageOptions {
  * The advantage of using this instead of cookie session storage is that
  * KV Store may contain much more data than cookies.
  */
-export function createCloudflareKVSessionStorage({
+export function createWorkersKVSessionStorage({
   cookie,
   kv,
-}: CloudflareKVSessionStorageOptions): SessionStorage {
+}: WorkersKVSessionStorageOptions): SessionStorage {
   return createSessionStorage({
     cookie,
     async createData(data, expires) {
diff --git a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts
index 810c810bb..5cae22956 100644
--- a/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts
+++ b/packages/remix-dev/codemod/replace-remix-magic-imports/utils/export.ts
@@ -100,7 +100,10 @@ const defaultRuntimeExports: ExportNames = {
 
 const exportNamesByRuntime: Record<Runtime, Partial<ExportNames>> = {
   cloudflare: {
-    value: ["createCloudflareKVSessionStorage"],
+    value: [
+      "createCloudflareKVSessionStorage",
+      "createWorkersKVSessionStorage",
+    ],
   },
   node: {
     type: ["HeadersInit", "RequestInfo", "RequestInit", "ResponseInit"],
diff --git a/packages/remix-dev/compiler/utils/fs.ts b/packages/remix-dev/compiler/utils/fs.ts
index bf38d480a..c64ac0622 100644
--- a/packages/remix-dev/compiler/utils/fs.ts
+++ b/packages/remix-dev/compiler/utils/fs.ts
@@ -9,17 +9,3 @@ export async function writeFileSafe(
   await fsp.writeFile(file, contents);
   return file;
 }
-
-export async function writeFilesSafe(
-  files: { file: string; contents: string }[]
-): Promise<string[]> {
-  return Promise.all(
-    files.map(({ file, contents }) => writeFileSafe(file, contents))
-  );
-}
-
-export async function createTemporaryDirectory(
-  baseDir: string
-): Promise<string> {
-  return fsp.mkdtemp(path.join(baseDir, "remix-"));
-}
diff --git a/packages/remix-dev/config.ts b/packages/remix-dev/config.ts
index c41db0e61..c2a5ef257 100644
--- a/packages/remix-dev/config.ts
+++ b/packages/remix-dev/config.ts
@@ -307,14 +307,14 @@ export async function readConfig(
   remixRoot?: string,
   serverMode = ServerMode.Production
 ): Promise<RemixConfig> {
-  if (!remixRoot) {
-    remixRoot = process.env.REMIX_ROOT || process.cwd();
-  }
-
   if (!isValidServerMode(serverMode)) {
     throw new Error(`Invalid server mode "${serverMode}"`);
   }
 
+  if (!remixRoot) {
+    remixRoot = process.env.REMIX_ROOT || process.cwd();
+  }
+
   let rootDirectory = path.resolve(remixRoot);
   let configFile = findConfig(rootDirectory, "remix.config");
 
@@ -450,15 +450,13 @@ export async function readConfig(
       appDirectory,
       appConfig.ignoredRouteFiles
     );
-    for (let key of Object.keys(conventionalRoutes)) {
-      let route = conventionalRoutes[key];
+    for (let route of Object.values(conventionalRoutes)) {
       routes[route.id] = { ...route, parentId: route.parentId || "root" };
     }
   }
   if (appConfig.routes) {
     let manualRoutes = await appConfig.routes(defineRoutes);
-    for (let key of Object.keys(manualRoutes)) {
-      let route = manualRoutes[key];
+    for (let route of Object.values(manualRoutes)) {
       routes[route.id] = { ...route, parentId: route.parentId || "root" };
     }
   }
diff --git a/packages/remix-eslint-config/rules/packageExports.js b/packages/remix-eslint-config/rules/packageExports.js
index bbef0084c..a3c02efe3 100644
--- a/packages/remix-eslint-config/rules/packageExports.js
+++ b/packages/remix-eslint-config/rules/packageExports.js
@@ -66,7 +66,7 @@ const architectSpecificExports = {
 };
 
 const cloudflareSpecificExports = {
-  value: ["createCloudflareKVSessionStorage"],
+  value: ["createCloudflareKVSessionStorage", "createWorkersKVSessionStorage"],
   type: [],
 };
 
diff --git a/packages/remix-react/index.tsx b/packages/remix-react/index.tsx
index 8387150d9..e0f349836 100644
--- a/packages/remix-react/index.tsx
+++ b/packages/remix-react/index.tsx
@@ -70,6 +70,7 @@ export { useCatch } from "./errorBoundaries";
 
 export type { HtmlLinkDescriptor } from "./links";
 export type {
+  CatchBoundaryComponent,
   HtmlMetaDescriptor,
   RouteModules as UNSAFE_RouteModules,
   ShouldReloadFunction,
diff --git a/packages/remix-server-runtime/package.json b/packages/remix-server-runtime/package.json
index 881088ab3..f943add14 100644
--- a/packages/remix-server-runtime/package.json
+++ b/packages/remix-server-runtime/package.json
@@ -18,6 +18,7 @@
   "dependencies": {
     "@remix-run/router": "1.3.0",
     "@types/cookie": "^0.4.0",
+    "@types/react": "^18.0.15",
     "@web3-storage/multipart-parser": "^1.0.0",
     "cookie": "^0.4.1",
     "set-cookie-parser": "^2.4.8",
@@ -25,13 +26,7 @@
   },
   "devDependencies": {
     "@remix-run/web-file": "^3.0.2",
-    "@types/set-cookie-parser": "^2.4.1",
-    "react": "^18.2.0",
-    "react-dom": "^18.2.0"
-  },
-  "peerDependencies": {
-    "react": ">=16.8",
-    "react-dom": ">=16.8"
+    "@types/set-cookie-parser": "^2.4.1"
   },
   "engines": {
     "node": ">=14"
diff --git a/packages/remix-server-runtime/routeModules.ts b/packages/remix-server-runtime/routeModules.ts
index 933a2390e..380b2549d 100644
--- a/packages/remix-server-runtime/routeModules.ts
+++ b/packages/remix-server-runtime/routeModules.ts
@@ -1,5 +1,5 @@
-import type { ComponentType } from "react";
 import type { Location, Params } from "@remix-run/router";
+import type { ComponentType } from "react";
 
 import type { AppLoadContext, AppData } from "./data";
 import type { LinkDescriptor } from "./links";
@@ -37,7 +37,7 @@ export interface ActionFunction {
 /**
  * A React component that is rendered when the server throws a Response.
  */
-export type CatchBoundaryComponent = ComponentType<{}>;
+export type CatchBoundaryComponent = ComponentType;
 
 /**
  * A React component that is rendered when there is an error on a route.
diff --git a/rollup.utils.js b/rollup.utils.js
index 7e415b3d7..d8c352620 100644
--- a/rollup.utils.js
+++ b/rollup.utils.js
@@ -267,6 +267,7 @@ function getMagicExports(packageName) {
         "createCookieSessionStorage",
         "createMemorySessionStorage",
         "createSessionStorage",
+        "createWorkersKVSessionStorage",
       ],
     },
     "@remix-run/node": {


Test patch:
diff --git a/integration/cf-compiler-test.ts b/integration/cf-compiler-test.ts
index a1d058e98..74c8ae529 100644
--- a/integration/cf-compiler-test.ts
+++ b/integration/cf-compiler-test.ts
@@ -155,6 +155,7 @@ test.describe("cloudflare compiler", () => {
       "createMemorySessionStorage",
       "createSessionStorage",
       "createSession",
+      "createWorkersKVSessionStorage",
       "isCookie",
       "isSession",
       "json",
diff --git a/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts b/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts
index e508c792d..2afa427c6 100644
--- a/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts
+++ b/packages/remix-dev/__tests__/transform-replaceRemixMagicImports-test.ts
@@ -61,7 +61,7 @@ it("replaces multi-kind, multi-specifier imports", async () => {
 
 it("replaces runtime-specific and adapter-specific imports", async () => {
   let code = [
-    'import { json, createCloudflareKVSessionStorage, createRequestHandler, createPagesFunctionHandler, Form } from "remix"',
+    'import { json, createWorkersKVSessionStorage, createRequestHandler, createPagesFunctionHandler, Form } from "remix"',
     'import type { ActionFunction, GetLoadContextFunction, createPagesFunctionHandlerParams, LinkProps } from "remix"',
   ].join("\n");
   let transform = replaceRemixMagicImports({
@@ -71,7 +71,7 @@ it("replaces runtime-specific and adapter-specific imports", async () => {
   let result = eol.normalize(transform(code, "fake.tsx"));
   expect(result).toBe(
     [
-      'import { type ActionFunction, createCloudflareKVSessionStorage, json } from "@remix-run/cloudflare";',
+      'import { type ActionFunction, createWorkersKVSessionStorage, json } from "@remix-run/cloudflare";',
       "", // recast adds a newline here https://github.com/benjamn/recast/issues/39
       "import {",
       "  type GetLoadContextFunction,",