Skip to content

fix: Prevent ReferenceError for id in workerApi.js example.#5307

Merged
ryanking13 merged 1 commit intopyodide:mainfrom
dfrtz:webworkerid
Jan 11, 2025
Merged

fix: Prevent ReferenceError for id in workerApi.js example.#5307
ryanking13 merged 1 commit intopyodide:mainfrom
dfrtz:webworkerid

Conversation

@dfrtz
Copy link
Contributor

@dfrtz dfrtz commented Jan 8, 2025

Description

Example code for workerApi current fails due to local variable referencing. This is what happens right now if using the examples as-is:

Uncaught ReferenceError: Cannot access 'id' before initialization at Worker.listener (workerApi.js:23:28)
listener	@	workerApi.js:23

It appears to have been because it is trying to use "id" from:

const { id, ...rest } = data;

Instead of using the id outside the closure. If the id variable outside is changed (or inside), then it works. I chose to update the one outside to hopefully make it clearer. With this change, no more crash using the example.

I did not notice any open PRs or Issues for this, apologies if I overlooked anything.

Checklists

  • Add new / update outdated documentation

Copy link
Member

@ryanking13 ryanking13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ryanking13 ryanking13 merged commit be56903 into pyodide:main Jan 11, 2025
42 checks passed
@ryanking13
Copy link
Member

Thanks again!

@dfrtz dfrtz deleted the webworkerid branch January 11, 2025 03:55
hoodmane pushed a commit that referenced this pull request Jan 13, 2025
Co-authored-by: David Fritz <dfritz@purestorage.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants