Closed mwszekely closed 1 year ago
Nice work thank you I believe this should also fix #616. I'll get a nodejs test written for this tomorrow and get a patch release out.
Replacing **self**
with **globalThis**
creates problems in older versions.
var getGlobal = function () { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } throw new Error('unable to locate global object'); };
Selecting the available global object using the above function will resolve this issue.
This is to fix runtime errors that occur when Comlink is used in a
Worklet
becauseself
doesn't exist there.I ran into a problem suddenly using Comlink in an
AudioWorklet
getting runtime errors on line 425 because it's looking for the existence of a property on theself
object -- sinceself
isn't available inWorklet
s I just replaced it withglobalThis
and it resolved the issue.(The suddenness of it was just an unrelated tree-shaking issue -- ifI completely misunderstood the timing and presumably need to get some sleep 🙃expose
is optimized out by whatever bundler you're using then theWorklet
never inspectsself
, and never crashes. It's possible that this issue could suddenly affect others if they change how they use Comlink in their projects, even without callingexpose
)