Skip to content

Commit ede8523

Browse files
client
1 parent 685e8be commit ede8523

9 files changed

Lines changed: 653 additions & 502 deletions

File tree

apps/server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
},
3333
"devDependencies": {
3434
"@effect/language-service": "catalog:",
35+
"@effect/platform-bun": "catalog:",
3536
"@effect/vitest": "catalog:",
3637
"@t3tools/contracts": "workspace:*",
3738
"@t3tools/shared": "workspace:*",

apps/server/src/server.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import * as Net from "node:net";
22
import * as Http from "node:http";
33

4-
import * as NodeHttpClient from "@effect/platform-node/NodeHttpClient";
54
import * as NodeHttpServer from "@effect/platform-node/NodeHttpServer";
65
import * as NodeServices from "@effect/platform-node/NodeServices";
6+
import * as BunServices from "@effect/platform-bun/BunServices";
7+
import * as BunHttpServer from "@effect/platform-bun/BunHttpServer";
78
import { Effect, Layer, Path } from "effect";
8-
import { HttpRouter, HttpServer } from "effect/unstable/http";
9+
import { FetchHttpClient, HttpRouter, HttpServer } from "effect/unstable/http";
910

10-
import { ServerConfig } from "./config";
11+
import { ServerConfig, ServerConfigShape } from "./config";
1112
import { attachmentsRouteLayer, healthRouteLayer, staticAndDevRouteLayer } from "./http";
1213
import { fixPath } from "./os-jank";
1314
import { websocketRpcRouteLayer } from "./ws";
@@ -133,6 +134,20 @@ const runtimeServicesLayer = Layer.empty.pipe(
133134
Layer.provideMerge(ServerLifecycleEventsLive),
134135
);
135136

137+
const HttpServerLive =
138+
typeof Bun !== "undefined"
139+
? (listenOptions: ServerConfigShape) =>
140+
BunHttpServer.layer({
141+
port: listenOptions.port,
142+
...(listenOptions.host ? { hostname: listenOptions.host } : {}),
143+
})
144+
: (listenOptions: ServerConfigShape) =>
145+
NodeHttpServer.layer(Http.createServer, {
146+
host: listenOptions.host,
147+
port: listenOptions.port,
148+
});
149+
const ServicesLive = typeof Bun !== "undefined" ? BunServices.layer : NodeServices.layer;
150+
136151
export const makeRoutesLayer = Layer.mergeAll(
137152
healthRouteLayer,
138153
attachmentsRouteLayer,
@@ -143,10 +158,9 @@ export const makeRoutesLayer = Layer.mergeAll(
143158
export const makeServerLayer = Layer.unwrap(
144159
Effect.gen(function* () {
145160
const config = yield* ServerConfig;
146-
const listenOptions: Net.ListenOptions = config.host
147-
? { host: config.host, port: config.port }
148-
: { port: config.port };
149-
yield* Effect.sync(fixPath);
161+
162+
fixPath();
163+
150164
const httpListeningLayer = Layer.effectDiscard(
151165
Effect.gen(function* () {
152166
yield* HttpServer.HttpServer;
@@ -164,10 +178,10 @@ export const makeServerLayer = Layer.unwrap(
164178

165179
return serverApplicationLayer.pipe(
166180
Layer.provideMerge(runtimeServicesLayer),
167-
Layer.provideMerge(NodeHttpClient.layerUndici),
168-
Layer.provideMerge(NodeServices.layer),
169-
Layer.provideMerge(NodeHttpServer.layer(Http.createServer, listenOptions)),
170-
Layer.provide(ServerLoggerLive.pipe(Layer.provide(NodeServices.layer))),
181+
Layer.provideMerge(HttpServerLive(config)),
182+
Layer.provide(ServerLoggerLive),
183+
Layer.provideMerge(FetchHttpClient.layer),
184+
Layer.provideMerge(ServicesLive),
171185
);
172186
}),
173187
);

apps/web/src/routes/__root.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ function EventRouter() {
142142
const pathnameRef = useRef(pathname);
143143
const handledBootstrapThreadIdRef = useRef<string | null>(null);
144144

145-
pathnameRef.current = pathname;
145+
useEffect(() => {
146+
pathnameRef.current = pathname;
147+
}, [pathname]);
146148

147149
useEffect(() => {
148150
const api = readNativeApi();
@@ -259,9 +261,9 @@ function EventRouter() {
259261
// during subscribe. Skip the toast for that replay so effect re-runs
260262
// don't produce duplicate toasts.
261263
let subscribed = false;
262-
const unsubServerConfigUpdated = onServerConfigUpdated((payload) => {
264+
const unsubServerConfigUpdated = onServerConfigUpdated((payload, source) => {
263265
void queryClient.invalidateQueries({ queryKey: serverQueryKeys.config() });
264-
if (!subscribed) return;
266+
if (!subscribed || source !== "keybindingsUpdated") return;
265267
const issue = payload.issues.find((entry) => entry.kind.startsWith("keybindings."));
266268
if (!issue) {
267269
toastManager.add({

0 commit comments

Comments
 (0)