Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use postMessage instead of a comlink produced MessageChannel #148

Merged
merged 5 commits into from
Dec 17, 2024

Conversation

martenrichter
Copy link
Contributor

@martenrichter martenrichter commented Dec 15, 2024

Copy link
Contributor

lite-badge 👈 Try it on ReadTheDocs

@martenrichter
Copy link
Contributor Author

This is an alternative to:
#144
and should fix the current problems, if comlink is used.
Should fix #143 and related reports.

@jtpio jtpio added the bug Something isn't working label Dec 16, 2024
super();
this._sendWorkerMessage = (msg: any) => {
// use postMessage, but in a format, that comlink would not process.
postMessage({ jMsg: msg });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if something a bit more explicit like _kernelMessage could also work? With or without the leading _, but having it could help communicate it's used for "internal" message handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but then also the coincident worker needs to rename the change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant for the jMsg key, we could still keep _sendWorkerMessage as the method name:

Suggested change
postMessage({ jMsg: msg });
postMessage({ _kernelMessage: msg });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. and it is also unique enough that comlink ignores it. (comlink ignores it if no id field is set...)

yarn.lock Outdated
version: 4.4.1
resolution: "comlink@npm:4.4.1"
checksum: 16d58a8f590087fc45432e31d6c138308dfd4b75b89aec0b7f7bb97ad33d810381bd2b1e608a1fb2cf05979af9cbfcdcaf1715996d5fcf77aeb013b6da3260af
languageName: node
linkType: hard

"comlink@npm:^4.4.2":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the two versions of comlink could be deduplicated with:

"deduplicate": "yarn-berry-deduplicate -s fewer --fail",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I will try this. I am not so fluent with yarn, I normally use npm. I'll be back in the evening at my dev computer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running jlpm deduplicate at the top-level should normally perform the deduplication step.

@jtpio jtpio added this to the 0.4.x milestone Dec 16, 2024
@martenrichter
Copy link
Contributor Author

OK, I have included the suggested changes. The deduplication affected more than just the comlink package, I hope this is fine.

Copy link
Member

@jtpio jtpio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

On the current jupyterlite demo site:

jupyterlite-widgets-interact.webm

With this PR and the same notebook, it does seem to fix the interact issue 👍

jupyterlite-widgets-interact-fix.webm

@jtpio jtpio merged commit 0164b59 into jupyterlite:main Dec 17, 2024
13 checks passed
@jtpio
Copy link
Member

jtpio commented Dec 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants