Skip to content

Commit 9eb35f2

Browse files
committed
migrate to react-router
1 parent 98af0e7 commit 9eb35f2

File tree

7 files changed

+33
-41
lines changed

7 files changed

+33
-41
lines changed

src/cloudflare.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { Context } from "hono";
22

3+
import { createWorkersKVSessionStorage } from "@react-router/cloudflare";
4+
import { createMiddleware } from "hono/factory";
5+
import { cacheHeader } from "pretty-cache-header";
36
import {
47
CookieOptions,
58
SessionData,
6-
createWorkersKVSessionStorage,
79
createCookieSessionStorage,
8-
} from "@remix-run/cloudflare";
9-
import { createMiddleware } from "hono/factory";
10-
import { cacheHeader } from "pretty-cache-header";
10+
} from "react-router";
1111

1212
import { session } from "./session.js";
1313

src/handler.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import type { AppLoadContext, ServerBuild } from "@remix-run/server-runtime";
21
import type { Context } from "hono";
2+
import type { AppLoadContext, ServerBuild } from "react-router";
33

4-
import { createRequestHandler } from "@remix-run/server-runtime";
54
import { createMiddleware } from "hono/factory";
5+
import { createRequestHandler } from "react-router";
66

77
export interface RemixMiddlewareOptions {
88
build: ServerBuild;
@@ -25,4 +25,4 @@ export function remix({
2525
});
2626
}
2727

28-
export { createRequestHandler } from "@remix-run/server-runtime";
28+
export { createRequestHandler } from "react-router";

src/i18next.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import type { Context } from "hono";
22
import type { RemixI18NextOption } from "remix-i18next/server";
33

44
import { createMiddleware } from "hono/factory";
5-
import { Namespace, TFunction } from "i18next";
5+
import { FlatNamespace, TFunction } from "i18next";
66
import { RemixI18Next } from "remix-i18next/server";
77

8-
const i18nSymbol = Symbol();
9-
const LocaleSymbol = Symbol();
10-
const TSymbol = Symbol();
8+
const i18nSymbol = Symbol().toString();
9+
const LocaleSymbol = Symbol().toString();
10+
const TSymbol = Symbol().toString();
1111

1212
export function i18next(options: RemixI18NextOption | RemixI18Next) {
1313
return createMiddleware(async (c, next) => {
@@ -46,10 +46,9 @@ i18next.getLocale = function getLocale(c: Context) {
4646
return locale;
4747
};
4848

49-
i18next.getFixedT = function getFixedT<Ns extends Namespace = "translation">(
50-
c: Context,
51-
{ namespace }: { namespace?: Ns } = {},
52-
) {
49+
i18next.getFixedT = function getFixedT<
50+
Ns extends FlatNamespace = "translation",
51+
>(c: Context, { namespace }: { namespace?: Ns } = {}) {
5352
// If `namespace` is set, we return a new `t` function that is bound to the
5453
// given namespace. Otherwise, we return the default `t` function.
5554
if (namespace) {

src/session.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import type {
2-
Session,
3-
SessionData,
4-
SessionStorage,
5-
} from "@remix-run/server-runtime";
61
import type { Context } from "hono";
2+
import type { Session, SessionData, SessionStorage } from "react-router";
73

84
import { createMiddleware } from "hono/factory";
95

10-
const sessionStorageSymbol = Symbol();
11-
const sessionSymbol = Symbol();
6+
const sessionStorageSymbol = Symbol().toString();
7+
const sessionSymbol = Symbol().toString();
128

139
export function session<Data = SessionData, FlashData = Data>(options: {
1410
autoCommit?: boolean;

test/cloudflare.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import {
2-
createCookieSessionStorage,
3-
createWorkersKVSessionStorage,
4-
} from "@remix-run/cloudflare";
1+
import { createWorkersKVSessionStorage } from "@react-router/cloudflare";
52
import { Context } from "hono";
63
import { createMiddleware } from "hono/factory";
4+
import { createCookieSessionStorage } from "react-router";
75
import { describe, test, expect, vi, beforeEach, afterAll } from "vitest";
86

97
import {
@@ -13,9 +11,13 @@ import {
1311
} from "../src/cloudflare";
1412
import { session } from "../src/session";
1513

16-
vi.mock("@remix-run/cloudflare", () => {
14+
vi.mock("@react-router/cloudflare", () => {
1715
return {
1816
createWorkersKVSessionStorage: vi.fn(),
17+
};
18+
});
19+
vi.mock("react-router", () => {
20+
return {
1921
createCookieSessionStorage: vi.fn(),
2022
};
2123
});

test/handler.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ServerBuild } from "@remix-run/server-runtime";
1+
import type { ServerBuild } from "react-router";
22

33
import { Hono } from "hono";
44
import { describe, test, expect, vi, beforeEach, afterAll } from "vitest";
@@ -29,11 +29,7 @@ const build = {
2929
default: () => new Response("body"),
3030
},
3131
},
32-
future: {
33-
v3_fetcherPersist: true,
34-
v3_relativeSplatPath: true,
35-
v3_throwAbortReason: true,
36-
},
32+
future: {},
3733
publicPath: "/",
3834
routes: {
3935
root: {
@@ -45,7 +41,6 @@ const build = {
4541
},
4642
},
4743
isSpaMode: false,
48-
mode: "production",
4944
} satisfies ServerBuild;
5045

5146
describe(remix.name, () => {

test/session.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { createCookieSessionStorage } from "@remix-run/cloudflare";
21
import { Context } from "hono";
2+
import { createCookieSessionStorage } from "react-router";
33
import { describe, test, expect, vi, beforeEach, afterAll } from "vitest";
44

55
import { getSession, getSessionStorage, session } from "../src/session";
66

7-
vi.mock("@remix-run/node", () => {
7+
vi.mock("@react-router/node", () => {
88
return {
99
createCookieSessionStorage: vi.fn(),
1010
};
@@ -64,7 +64,7 @@ describe(session.name, () => {
6464
expect(createSessionStorage).toHaveBeenCalledOnce();
6565
expect(c.set).toHaveBeenNthCalledWith(
6666
1,
67-
expect.any(Symbol),
67+
expect.any(String),
6868
sessionStorage,
6969
);
7070
expect(next).toHaveBeenCalledOnce();
@@ -84,7 +84,7 @@ describe(session.name, () => {
8484
expect(createSessionStorage).toHaveBeenCalledOnce();
8585
expect(c.set).toHaveBeenNthCalledWith(
8686
1,
87-
expect.any(Symbol),
87+
expect.any(String),
8888
sessionStorage,
8989
);
9090
expect(spy.getSession).toHaveBeenCalledOnce();
@@ -93,7 +93,7 @@ describe(session.name, () => {
9393

9494
expect(c.set).toHaveBeenNthCalledWith(
9595
2,
96-
expect.any(Symbol),
96+
expect.any(String),
9797
sessionInContext,
9898
);
9999
expect(next).toHaveBeenCalledOnce();
@@ -121,7 +121,7 @@ describe(getSessionStorage.name, () => {
121121
"A session middleware was not set.",
122122
);
123123

124-
expect(c.get).toHaveBeenCalledWith(expect.any(Symbol));
124+
expect(c.get).toHaveBeenCalledWith(expect.any(String));
125125
});
126126

127127
test("returns session storage", async () => {
@@ -147,7 +147,7 @@ describe(getSession.name, () => {
147147
"A session middleware was not set.",
148148
);
149149

150-
expect(c.get).toHaveBeenCalledWith(expect.any(Symbol));
150+
expect(c.get).toHaveBeenCalledWith(expect.any(String));
151151
});
152152

153153
test("returns session", async () => {

0 commit comments

Comments
 (0)