From d800d065d61a65bdd3e557240f19b55ea56e1cb9 Mon Sep 17 00:00:00 2001 From: "Anthony Fu (via agent)" Date: Tue, 6 Oct 2026 05:19:10 +0000 Subject: [PATCH] docs: fix two module guide snippets that do not work as written The dock handle example used ctx outside onDevtoolsReady, and the RPC example broadcast once from devtools:ready, which runs before any client is connected, so the message never arrived. Broadcast on a change instead. --- docs/content/2.module/0.guide.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/content/2.module/0.guide.md b/docs/content/2.module/0.guide.md index e038e13ab5..4f03d1e2ec 100644 --- a/docs/content/2.module/0.guide.md +++ b/docs/content/2.module/0.guide.md @@ -46,8 +46,10 @@ Set `category` (`app`, `analyze`, `server`, `modules`, `documentation`, `advance `register()` returns a handle to patch the entry later, for example to show a badge: ```ts -const entry = ctx.docks.register({ id: 'my-module', /* ... */ }) -entry.update({ badge: '3' }) +onDevtoolsReady((ctx) => { + const entry = ctx.docks.register({ id: 'my-module', /* ... */ }) + entry.update({ badge: '3' }) +}) ``` Learn more about [DevTools Utility Kit](/module/utils-kit). @@ -112,9 +114,11 @@ export default defineNuxtModule({ }, }) - // call client RPC functions - // since there might be multiple clients connected, `broadcast` calls all of them - rpc.broadcast({ method: 'show-notification', args: ['Hello from My Module!'], event: true }) + // call client RPC functions when something changes; `broadcast` reaches + // every connected client (none are connected yet when this hook runs) + nuxt.hook('builder:watch', (_event, path) => { + rpc.broadcast({ method: 'show-notification', args: [`${path} changed`], event: true }) + }) }) }, })