Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions packages/core/playground/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,34 @@ export default defineConfig({
initialValue: { count: 1 },
})

setInterval(() => {
counterState.mutate((current) => {
current.count = (current.count + 1) % 5
})
const count = counterState.value().count
counterState.on('updated', (newState) => {
ctx.docks.update({
id: 'counter',
type: 'action',
icon: `material-symbols:counter-${count}`,
title: `Counter ${count}`,
// TODO: HMR?
icon: `material-symbols:counter-${newState.count}`,
title: `Counter ${newState.count}`,
action: ctx.utils.createSimpleClientScript(`() => {
alert('Counter ${count}')
alert('Counter ${newState.count}')
}`),
})
}, 1000)
})

// setInterval(() => {
// counterState.mutate((current) => {
// current.count = (current.count + 1) % 5
// })
// const count = counterState.value().count
// ctx.docks.update({
// id: 'counter',
// type: 'action',
// icon: `material-symbols:counter-${count}`,
// title: `Counter ${count}`,
// // TODO: HMR?
// action: ctx.utils.createSimpleClientScript(`() => {
// alert('Counter ${count}')
// }`),
// })
// }, 1000)
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/node/__tests__/host-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ describe('rpcFunctionsHost', () => {
})).resolves.toBeUndefined()
})

it('should throw in dev mode', async () => {
it('should not throw in dev mode when rpc group is not yet set', async () => {
const host = new RpcFunctionsHost({ mode: 'dev' } as DevToolsNodeContext)
await expect(host.broadcast({
method: 'devtoolskit:internal:terminals:updated',
args: [],
})).rejects.toThrow('RpcFunctionsHost] RpcGroup is not set')
})).resolves.toBeUndefined()
})
})

Expand Down
7 changes: 2 additions & 5 deletions packages/core/src/node/host-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,8 @@ export class RpcFunctionsHost extends RpcFunctionsCollectorBase<DevToolsRpcServe
>(
options: RpcBroadcastOptions<T, Args>,
): Promise<void> {
if (!this._rpcGroup) {
if (this.context.mode === 'build')
return
throw new Error('RpcFunctionsHost] RpcGroup is not set, it likely to be an internal bug of Vite DevTools')
}
if (!this._rpcGroup)
return

debugBroadcast(JSON.stringify(options.method))

Expand Down
Loading