diff --git a/src/bun.js/api/BunObject.zig b/src/bun.js/api/BunObject.zig index 60a13a1e83..07d6c690f2 100644 --- a/src/bun.js/api/BunObject.zig +++ b/src/bun.js/api/BunObject.zig @@ -1086,6 +1086,9 @@ pub fn serve(globalObject: *jsc.JSGlobalObject, callframe: *jsc.CallFrame) bun.J if (route_list_object != .zero) { ServerType.js.routeListSetCached(obj, globalObject, route_list_object); } + if (config.websocket_js_context != .zero) { + ServerType.js.websocketServerContextSetCached(obj, globalObject, config.websocket_js_context); + } server.js_value.setStrong(obj, globalObject); if (config.allow_hot) { diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig index 183d1bab3e..1a4266616d 100644 --- a/src/bun.js/api/server.zig +++ b/src/bun.js/api/server.zig @@ -2726,14 +2726,6 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d httplog("listen", .{}); var app: *App = undefined; const globalThis = this.globalThis; - - // Set the websocketServerContext on the server JSValue to keep it alive through GC - if (this.config.websocket_js_context != .zero) { - const server_value = this.jsValueAssertAlive(); - const js = bun.JSC.Codegen.JSHTTPServerClass(comptime protocol, comptime development); - js.websocketServerContextSetCachedValue(server_value, globalThis, this.config.websocket_js_context); - } - var route_list_value = jsc.JSValue.zero; if (ssl_enabled) { bun.BoringSSL.load();