useWorker
useWorker copied to clipboard
useWorker error when destructuring function arguments
[Required] Describe the bug When passing a function to useWorker that has argument destructuring I get the error shown on the screenshot.
[Optional] To Reproduce Steps to reproduce the behavior:
- Go to https://codesandbox.io/s/useworker-argument-destructuring-guznf
- Click on "Run test"
- See error
[Required] Expected behavior Destructuring function arguments break the worker.
[Optional] Screenshots
This is the error I get in my project:
I'm also having issues composing functions because I get this error:
Hi @juansalvatore! Thanks for reporting
This seems to be an issue with browser compatibility and transpiling. What is probably happening is that your build (and CodeSandbox's) is targeted to browsers previous to array destructuring so it gets transpiled and that invokes some functions which are not available on worker side. (The reference error mentioning babel you're seeing in the error message)
The second bug you're mentioning seems to be related to functions not being available on the worker side. We're now working on support for those! 😄 (details in #98)
Let me see if I can make a repro locally and make changes from our side to make it work, or at least add some warnings
@zant Any update on this?
This is due to webpack transpiling your code. When you use ...
to destructure an array, webpack will transpile this code, and change ...
to use some other utility to copy the array. This will make your function impure.