useWorker icon indicating copy to clipboard operation
useWorker copied to clipboard

useWorker error when destructuring function arguments

Open juansalvatore opened this issue 4 years ago • 5 comments

[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:

  1. Go to https://codesandbox.io/s/useworker-argument-destructuring-guznf
  2. Click on "Run test"
  3. See error

[Required] Expected behavior Destructuring function arguments break the worker.

[Optional] Screenshots This is the error I get in my project: image

juansalvatore avatar Dec 17 '20 16:12 juansalvatore

I'm also having issues composing functions because I get this error: image

juansalvatore avatar Dec 17 '20 17:12 juansalvatore

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)

zant avatar Jan 12 '21 15:01 zant

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 avatar Jan 12 '21 15:01 zant

@zant Any update on this?

kvpasupuleti avatar May 25 '21 16:05 kvpasupuleti

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.

ashish-r avatar May 21 '22 07:05 ashish-r