-
Notifications
You must be signed in to change notification settings - Fork 263
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
Use --target=web
for WebWorkers
#624
Conversation
I am wondering why that is necessary. According to the https://rustwasm.github.io/wasm-bindgen/examples/wasm-in-web-worker.html:
I am not sure this is true anymore: https://bugzilla.mozilla.org/show_bug.cgi?id=1247687 |
Thanks for those pointers, very useful. I actually didn't test with running the compiled code, only that trunk can compile it, my bad. It seems that the resulting code doesn't work on any of Chrome, Firefox or Safari. I get the errors
Investigating a bit more, I think that one would need to create the worker like this to avoid the error. Looking under the "options.type parameter" support table here I think that all but Safari support "modules in web workers" (i.e. the page you link is a bit outdated indeed). So the reason that my code breaks is that I'm using Building my project without a dependency on To summarize, I think that this PR should instead expose a config option to select between |
19045cd
to
0b1227e
Compare
@hamza1311 Would you be able to take a look too. IIRC you worked with the workers too. |
I explained my stance on it at rustwasm/gloo#421 (comment):
|
@hamza1311 @JonasAlaif so I guess it makes sense then to have this configurable and provide reasonable defaults. Basically what you did, but switching all default to |
Btw, I think it would help if you remove the |
8a9f041
to
558d92a
Compare
Sorry that I didn't cross-link the gloo PR, I was meaning to but forgot. |
There is one more issue: |
I think this is ready to be merged now (unless anyone spots any remaining issue). Changing the default will require everyone to either use the new |
@JonasAlaif before merging anything into trunk, I want to see how the situation about the governance of trunk resolves. Right now there the PR #623, which would bring back the changes from trunk-ng into trunk. Merging this PR would make merging the other even more painful. However, the other one cannot be merged since I don't have permission to merge (vs rebase) a PR. If that helps, you can rebase this PR on |
Yep sounds reasonable, the rebased one on |
I don't remember the details, but in general I did the minimum amount to get it to work, and I think the other targets might have had worse support back then. |
@JonasAlaif I think it needs to be rebased after the trunk-ng merge. Other than that, I think it's good to be merged. One thing that might be an improvement could be to fully parse the target into an enum, not sure that's worth it though. |
@ctron will do. I did try parsing it to an enum, but it was a bit awkward: one needs to implement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
I would only have a minor request. Could you format your commit message using "conventional commits": https://www.conventionalcommits.org/en/v1.0.0/#summary
In this case I think it's just prefixing the first line with feat:
, as it's adding a new feature.
BREAKING CHANGE: `data-type=worker` assets default to `--target web` instead of the old `no-modules` and thus such workers must be spawned with the option `type=module`.
Does that look ok? I added the "BREAKING CHANGE" thing with the changed default |
Yes that looks fine. But I wasn't fully aware that this would be a breaking change :) … But I think it could be easily turned into a non-breaking changing by using the old default, and put in a "todo" to change the default for 0.19.0. Sorry for spotting that so late. |
Ok, reading through the gloo issue, I've the feeling that changing the default makes sense. Breaking change or not. So hopefully it doesn't actually break anything … otherwise, sorry for doing so. But there seems an easy way back to the old setting. |
I rebased the PR and merged it directly to main in 9a9c970 |
Ok, I reverted the default to I will need to take a closer look into workers. But that takes more time and I would like the get out 0.18.1. |
@ctron no worries, the reason it's a breaking change is that For the Trunk examples, this would mean |
Ok, so I think it was good not making this a breaking change. I added an example for module based webworkers with your suggestions: #649 … at least for the plain webworker. To my understanding gloo needs to make some changes first. I updated the gloo dependencies anyway. |
I ran into the following error when using a web worker which uses a JS snippet (namely, using the
viz_js
crate in a web worker):I didn't dig into it too much, but this page seems to explain the issue. So, as this PR does, I tried to naively change to
--target=web
in trunk and this resolved the above error for me.Not sure why @kristoff3r chose to use
--target=no-modules
in #285, maybe there is some advantage? If there is some reason forno-modules
then it would at least be nice to be able to toggle this in a config.Checklist
site
content with pertinent info (may not always apply).