From 767cd4d564772097c1c200998de7b4257fdc8a3f Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 12 Jun 2024 23:56:50 -0500 Subject: [PATCH] feat: websocket HMR --- app/entry.server.jsx | 13 +++++++++---- server.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/entry.server.jsx b/app/entry.server.jsx index 2a865b7..2f82967 100644 --- a/app/entry.server.jsx +++ b/app/entry.server.jsx @@ -11,12 +11,17 @@ import { RemixServer } from "@remix-run/react"; import { isbot } from "isbot"; import { renderToPipeableStream } from "react-dom/server"; -import websocketServer from './websocket'; - const ABORT_DELAY = 5_000; -export async function websocket(server) { - await websocketServer(server); +export async function websocket(server, viteDevServer) { + if (viteDevServer) { + const {createViteRuntime} = await import('vite'); + const runtime = await createViteRuntime(viteDevServer); + (await runtime.executeEntrypoint('/app/websocket.js')).default(server); + } + else { + (await import('./websocket.js')).default(server); + } } export default function handleRequest( diff --git a/server.js b/server.js index 041b501..a2dee6b 100644 --- a/server.js +++ b/server.js @@ -49,7 +49,7 @@ const remixHandler = createRequestHandler({ build: () => ssr, }); -await ssr.entry.module.websocket(server); +await ssr.entry.module.websocket(server, viteDevServer); app.use(compression());