nuxt / devtools

Unleash Nuxt Developer Experience
https://devtools.nuxt.com
MIT License
2.93k stars 161 forks source link

fix: extendServerRpc does not register function #725

Closed rrd108 closed 2 months ago

rrd108 commented 2 months ago

🐛 The bug

When I use the example code for the docs to register a server rpc function it seems to be ignored.

If you start the project it will log a few messages to the console.

One of them will be RPC object: { broadcast: {} } and it is created by module.ts line 40.

🛠ī¸ To reproduce

https://stackblitz.com/~/github.com/rrd108/vue-mess-detector-nuxt-devtools

🌈 Expected behavior

The rpc object should have a getResults function registered.

ℹī¸ Additional context

The code here is almost the same what is in the docs. If I use the doc's code, I get the same result.

arashsheyda commented 2 months ago

@rrd108 you have to use extendClientRpc in your client side

make sure to use the same RPC_NAMESPACE in both client and server side (in your case vueMessDetector)

onDevtoolsClientConnected(async (client) => {
  const rpc = client.devtools.extendClientRpc<ServerFunctions, ClientFunctions>('vueMessDetector', {
    showNotification: (message) =>{
        // your logic
    },
  })

  result.value = await rpc.getResults()
})