-
Notifications
You must be signed in to change notification settings - Fork 380
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
Transfer handlers broke after upgrading to v4 #284
Comments
Hm, I might be able to fix that on Comlink’s side. Can you give me a minimal setup in a gist or something that reproduces this bug? Then I can turn it into a test. |
Here: http://next.plnkr.co/edit/jKM1kjMrb43XdbWM Check the console for errors. |
Looking at this now |
After digging into this a little bit, I don’t think I will fix this from Comlink’s side. The biggest change from v3 to v4 was to remove object traversals that were pretty costly, especially on low-end phones. To fix this, I’d have to either re-introduce traversals or give some special handling to That being said, you can work around this by giving your transfer handle the capability to traverse objects: Comlink.transferHandlers.set("ERROR", {
canHandle (obj) {
if(Array.isArray(obj)) {
return obj.some(el => this.canHandle(el));
}
return obj instanceof Error
},
serialize (obj) {
if(Array.isArray(obj)) {
return [obj.map(el => this.serialize(el)), []];
}
const message = obj && obj.message
const stack = obj && obj.stack
obj = Object.assign({}, obj, { message, stack })
return [obj, []]
},
deserialize (obj) {
if(Array.isArray(obj)) {
return obj.map(el => this.deserialize(el));
}
return Object.assign(Error(), obj)
}
}); (Demo & Code: https://comlink-issue-284.glitch.me/) I’m closing this, but please re-open if you disagree with my decision/reasoning :) |
I'm encountering a bug that appeared after migrating from v3 to v4. It's related to babel's transpilation and proxying callback functions with
Comlink.proxy
, (Comlink.proxyValue
in v3).Some context:
I declared a transfer handler for
Error
Here's a block of my source code where the bug occurs.
By this point,
fn
has been passed thruComlink.proxy
. In my debugging tests,arg
is a singleError
object. After thefn
is called with theError
arg, I expect my error transfer handler to handle it, which it does if my source code is running in the browser. That is, I expect the below func to return true.However, since i'm using babel, this is the code that runs in the browser.
The important bit is
fn(...args)
->fn.apply(void 0, args)
. This results in a different code path for the proxy. Instead of theapply
trap being called (which happens with my source), it results in theget
trap being called, and THEN theapply
trap.The bug: After upgrading to v4, the
obj
param incanHandle(obj)
is a single element array with the error obj, instead of the error obj itself.Here's a snippet of comlink's source with my comments to illustrate the differing code path:
Let me know if you need more info.
Is this something comlink can work around?
The text was updated successfully, but these errors were encountered: