jsonnull / electron-trpc

Build type-safe Electron inter-process communication using tRPC
https://electron-trpc.dev/
MIT License
267 stars 26 forks source link

`subscription.stop` method has no `input`, causing crash with superjson transformer #117

Closed jthrilly closed 1 year ago

jthrilly commented 1 year ago

I noticed a crash when using this lib with superjson. The stack trace indicated that superjson.deserialize was being called with the input being undefined.

A little digging and console logging led me to notice that this was happening for subscription.stop methods (which are being emitted here: https://github.com/jsonnull/electron-trpc/blob/main/packages/electron-trpc/src/renderer/ipcLink.ts#L77-L80) because they don't have an input property.

Thus when the handleIPCOperation function picks this up on the main thread, it is calling deserialize on an empty object (here: https://github.com/jsonnull/electron-trpc/blob/main/packages/electron-trpc/src/main/handleIPCOperation.ts#L23).

Seems like this function needs to look for the presence of operation.input before calling deserialize, or else filter by the operation method if it is a stable API.

jsonnull commented 1 year ago

Hey @jthrilly, thanks so much for reporting this issue! I don't think I would have personally run into this anytime soon 😅

Sorry for the delay getting back to you... I've pushed a patch up and it's out now in electron-trpc@0.4.2.

Please let me know if you have any more issues. Thanks again!