Skip to content

Commit d800d06

Browse files
committed
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.
1 parent 230cdda commit d800d06

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎docs/content/2.module/0.guide.md‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ Set `category` (`app`, `analyze`, `server`, `modules`, `documentation`, `advance
4646
`register()` returns a handle to patch the entry later, for example to show a badge:
4747

4848
```ts
49-
const entry = ctx.docks.register({ id: 'my-module', /* ... */ })
50-
entry.update({ badge: '3' })
49+
onDevtoolsReady((ctx) => {
50+
const entry = ctx.docks.register({ id: 'my-module', /* ... */ })
51+
entry.update({ badge: '3' })
52+
})
5153
```
5254

5355
Learn more about [DevTools Utility Kit](/module/utils-kit).
@@ -112,9 +114,11 @@ export default defineNuxtModule({
112114
},
113115
})
114116

115-
// call client RPC functions
116-
// since there might be multiple clients connected, `broadcast` calls all of them
117-
rpc.broadcast({ method: 'show-notification', args: ['Hello from My Module!'], event: true })
117+
// call client RPC functions when something changes; `broadcast` reaches
118+
// every connected client (none are connected yet when this hook runs)
119+
nuxt.hook('builder:watch', (_event, path) => {
120+
rpc.broadcast({ method: 'show-notification', args: [`${path} changed`], event: true })
121+
})
118122
})
119123
},
120124
})

0 commit comments

Comments
 (0)