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

Support naming worker with query suffix #12992

Closed
4 tasks done
tiamed opened this issue Apr 25, 2023 · 4 comments · Fixed by #14032
Closed
4 tasks done

Support naming worker with query suffix #12992

tiamed opened this issue Apr 25, 2023 · 4 comments · Fixed by #14032
Labels
contribution welcome enhancement New feature or request feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@tiamed
Copy link

tiamed commented Apr 25, 2023

Description

The workers loaded using ?worker is Untitled in chrome://inspect/#workers.
Need to provide an option for configuring the name.

Suggested solution

?worker&name=xxx

Alternative

new MyWorker({
  name: 'xxx',
});

Additional context

No response

Validations

@sapphi-red sapphi-red added enhancement New feature or request p2-nice-to-have Not breaking anything but nice to have (priority) feat: web workers and removed enhancement: pending triage labels Jun 4, 2023
@sapphi-red
Copy link
Member

It seems name param works with the Constructor one.

const worker = new Worker(new URL('./worker.js', import.meta.url), { name: 'foo' })

I think it makes sense to add to the Query Suffixes one too.

import MyWorker from './worker?worker'

const worker = new MyWorker({ name: 'foo' })

@ihch
Copy link
Contributor

ihch commented Jun 10, 2023

I didn't do the implementation with query suffix, but I implemented the naming method using a constructor.

Can I try to pull request?

(The query suffix implementation is having trouble with type definitions and I'm looking at this issue microsoft/TypeScript#38638 )
Capture

@sapphi-red
Copy link
Member

@ihch

There's two ways to create a worker in Vite. One is by the Constructors and the other is by the query suffixes.
The name param already works with the former one. But doesn't work with the latter one.

In my previous comment, I suggested to add the name param support for the query suffix one by passing a name param to the exported constructor. I guess you implemented in this way. I don't think we should support ?worker&name=foo so it's fine.

Anyway, pull requests are welcome and are recommended if you have a concrete code as it's easier to discuss.

@ihch
Copy link
Contributor

ihch commented Aug 6, 2023

Sorry for the delay!
I created a pull request. #14032

@github-actions github-actions bot locked and limited conversation to collaborators Sep 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome enhancement New feature or request feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants