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

Add customWorkerFactory to customize tsworker directly #4035

Closed
wants to merge 2 commits into from
Closed

Add customWorkerFactory to customize tsworker directly #4035

wants to merge 2 commits into from

Conversation

x6eull
Copy link

@x6eull x6eull commented Jun 21, 2023

Add a way to customize typescript worker in module workers, avoiding importScripts (which the customWorkerPath uses to extend the typescript worker).

Hoping to provide some progress to #3151.

@x6eull
Copy link
Author

x6eull commented Jun 21, 2023

@microsoft-github-policy-service agree

@hediet
Copy link
Member

hediet commented Jul 7, 2023

Afaik this approach does not work, as createData must be serializable. You cannot send over your customization function from the page to the worker.

@hediet hediet closed this Jul 7, 2023
@hediet
Copy link
Member

hediet commented Jul 7, 2023

Ah I think I understand, you want to provide a replacement for ts.worker.ts that calls create. But TypeScriptWorker is exported already by vs/language/typescript/tsWorker, so why don't you just implement your own create function that imports the exported TypeScriptWorker? This class is not exported in the ESM build.

@hediet hediet reopened this Jul 7, 2023
@hediet hediet enabled auto-merge July 7, 2023 15:35
Copy link
Member

@hediet hediet left a comment

Choose a reason for hiding this comment

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

I think it is a little bit ugly that you pass in unserializable data into the create function to override the TypeScriptWorker (and I hope nobody tries to pass in this data from the host side that creates the worker), but I don't see a much nicer solution.

@x6eull
Copy link
Author

x6eull commented Jul 7, 2023

@microsoft-github-policy-service agree

@hediet hediet disabled auto-merge July 7, 2023 15:41
@hediet
Copy link
Member

hediet commented Jul 7, 2023

I actually think #3488 is a better solution.

@hediet hediet closed this Jul 7, 2023
@x6eull
Copy link
Author

x6eull commented Jul 7, 2023

I had no idea that createData must be serializable when I created the pr. I couldn't build a complete package and test it, so I just followed the step of customWorkerPath. If createData must be serializable, this approach won't work since I intend to use it in the script that create the worker (as well as the editor).

@hediet
Copy link
Member

hediet commented Jul 7, 2023

If createData must be serializable,

It does not have to be serializable when called from a script that imports the worker, but the data the host passes in has to be serializable. So it would have worked in your use-case, but it could confuse users.
#3488 just exports everything needed for a solution that does not cause this confusion.

Thanks for coming up with this PR anyway! :)

@x6eull x6eull deleted the add-customworkerfactory branch July 7, 2023 16:10
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants