Skip to content

Commit

Permalink
chore: use devEnv.hot.handleInvoke
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Nov 7, 2024
1 parent d4af07b commit 39314cb
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions packages/workerd/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import {
DevEnvironment,
type HotChannel,
type HotChannelInvokeHandler,
type HotPayload,
type Plugin,
type ResolvedConfig,
Expand Down Expand Up @@ -125,8 +124,8 @@ export async function createWorkerdDevEnvironment(
unsafeEvalBinding: "__viteUnsafeEval",
serviceBindings: {
__viteInvoke: async (request) => {
const paylod = (await request.json()) as HotPayload;
const result = await invokeHandler(paylod);
const payload = (await request.json()) as HotPayload;
const result = await devEnv.hot.handleInvoke(payload);
return MiniflareResponse.json(result);
},
__viteRunnerSend: async (request) => {
Expand Down Expand Up @@ -175,18 +174,12 @@ export async function createWorkerdDevEnvironment(

// hmr channel
const hotListener = createHotListenerManager();
let invokeHandler: HotChannelInvokeHandler;
const hot: HotChannel = {
const transport: HotChannel = {
listen: () => {},
close: () => {},
on: hotListener.on,
off: hotListener.off,
send: runnerObject.__viteServerSend,
setInvokeHandler: (invokeHandler_) => {
if (invokeHandler_) {
invokeHandler = invokeHandler_;
}
},
};

// TODO: move initialization code to `init`?
Expand All @@ -199,7 +192,7 @@ export async function createWorkerdDevEnvironment(
}

const devEnv = new WorkerdDevEnvironmentImpl(name, config, {
transport: hot,
transport,
hot: true,
});

Expand Down

0 comments on commit 39314cb

Please sign in to comment.