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

fix: support UTF-8 encoding in inline Web Workers (fixes #12117) #12122

Closed
wants to merge 2 commits into from

Conversation

Simolation
Copy link

@Simolation Simolation commented Feb 20, 2023

Description

fixes #12117

This PR solves issue #12117, where inline Web Workers lose UTF-8 characters due to the atob function, which only supports ASCII. See https://developer.mozilla.org/en-US/docs/Glossary/Base64

The bug can be seen in this reproduction repo: https://stackblitz.com/edit/vitejs-vite-tyt9yp


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the PR Title Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).

@Simolation Simolation changed the title Fixes #12117 Support UTF-8 encoding in inline Web Workers (fixes #12117) Feb 20, 2023
@Simolation Simolation changed the title Support UTF-8 encoding in inline Web Workers (fixes #12117) fix: support UTF-8 encoding in inline Web Workers (fixes #12117) Feb 20, 2023
@jh0ker
Copy link

jh0ker commented Apr 14, 2023

Thank you, this fixed my problem at least :)

Copy link
Member

@sapphi-red sapphi-red left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!
Would you resolve conflicts and add a test for this somewhere inside playground/worker?

packages/vite/src/node/plugins/worker.ts Outdated Show resolved Hide resolved
@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels May 11, 2023
@sapphi-red
Copy link
Member

Note for reviewers: Uint8Array is supported by all browsers that supports Blob constructors. So the browser compat is fine.
https://caniuse.com/typedarrays
https://caniuse.com/blobbuilder

@xiaohk
Copy link
Contributor

xiaohk commented Jul 5, 2023

Thanks @Simolation! I think I face the same issue. How can I use your fix?

@sapphi-red
Copy link
Member

@xiaohk This PR needs the conflicts to be resolved and a test to be added. You can help this PR to be merged by contributing these changes.
Also you can use https://pnpm.io/cli/patch or https://www.npmjs.com/package/patch-package to patch your local Vite.

@xiaohk
Copy link
Contributor

xiaohk commented Feb 9, 2024

Hmm encountered the same error again 😭

@xiaohk
Copy link
Contributor

xiaohk commented Feb 10, 2024

I'd love to help. It seems I can't make changes to this PR, so I created a new PR #15866. @sapphi-red can you help review it please? Thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: web workers needs test p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Inline Web Worker looses special characters
6 participants