TypeFox / vscode-messenger

RPC messaging library for the VS Code extension platform
MIT License
33 stars 3 forks source link

Unable to send messages to parent `WebviewPanel` only #9

Closed thegecko closed 1 year ago

thegecko commented 1 year ago

We have an extension which can spawn multiple WebviewPanels with different data.

Switching to using vscode-messenger for the RPC between each WebViewPanel/View pair has uncovered an issue (or I haven't understood something!)

Using WebviewIdMessageParticipant in the panel allows messages to target just the view associated with it.

However, there is no way for the view to only target messages to its related panel. Using HOST_EXTENSION seems to broadcast messages to all created panels of that type.

This is fine for scenarios with a single WebViewPanel, but in our tests, the messaging breaks as soon as multiple WebViewPanels of the same type are created.

A PR for our extension demonstrating this issue can be found here:

https://github.com/eclipse-cdt-cloud/vscode-memory-inspector/pull/2

spoenemann commented 1 year ago

If I understand your issue correctly, you should be able to resolve it by specifying the sender option when adding a message handler, which was introduced in v0.4.3: messenger.ts

thegecko commented 1 year ago

Thanks, I'll take a look...

dhuebner commented 1 year ago

@thegecko Please take a look here https://github.com/eclipse-cdt-cloud/vscode-memory-inspector/pull/3/files There is an example how the sender can be used to "talk" to different webview panels

thegecko commented 1 year ago

Awesome, thanks for the PR, This now works as expected.

The only issue I see is an error in the console when closing the panel that the webview is disposed, but functionally everything is working fine.

dhuebner commented 1 year ago

@thegecko Make sure your handler are properly disposed, when a view is disposed. If it doesn't help please open an issue

thegecko commented 1 year ago

Make sure your handler are properly disposed, when a view is disposed. If it doesn't help please open an issue

I believe you included handler disposal in the panel on your PR, but the issue persisted. Do I need to dispose the handlers in the webview, too?

dhuebner commented 1 year ago

I believe you included handler disposal in the panel on your PR

Yes, I think so. Maybe I did something wrong there :) So probably one need to debug why an event was send to a closed view and by whom...

thegecko commented 1 year ago

So probably one need to debug why an event was send to a closed view and by whom...

I investigated this issue, and opened https://github.com/TypeFox/vscode-messenger/issues/10

dhuebner commented 1 year ago

@thegecko Very nice, thanks!