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

useWorker error when destructuring function arguments #97

Open
juansalvatore opened this issue Dec 17, 2020 · 5 comments
Open

useWorker error when destructuring function arguments #97

juansalvatore opened this issue Dec 17, 2020 · 5 comments
Assignees

Comments

@juansalvatore
Copy link

[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 juansalvatore added the bug Something isn't working label Dec 17, 2020
@juansalvatore
Copy link
Author

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

@zant zant added needs triage and removed bug Something isn't working labels Dec 17, 2020
@zant zant self-assigned this Dec 17, 2020
@zant
Copy link
Collaborator

zant commented Jan 12, 2021

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
Copy link
Collaborator

zant commented Jan 12, 2021

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

@KVPasupuleti
Copy link

@zant
Any update on this?

@ashish-r
Copy link
Contributor

ashish-r commented May 21, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants