-
Notifications
You must be signed in to change notification settings - Fork 795
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
Web Workers not working out of the box with certain bundlers #2731
Comments
@adamdbradley i noticed you recently released a couple of patches related to web workers. |
I too have this problem. Any update? cc @adamdbradley please? :) |
I reported a bug related to web workers a while ago #2914. It seems the web worker implementation could need some love :-( |
Bump this. Sorry for being annoying, but every time I see a new release (like 2.10.0 yesterday) and this still not addressed it feels bad, because the stencil way of writing WebWorkers is so clean compared to doing it manually, that it's such a shame it needs so many workarounds to get to work. |
Hey folks! Thank you for the patience. No timeline yet, but I tagged this to confirm the issue. One huge help would be yo make a reproduction repo for us, so we can quickly determine the problem and work out a solution. Can someone help us out by creating this? |
working on it. trying to get both webpack 4 and 5 since those are the ones I reported originally. |
@splitinfinities here you go: https://github.com/theo-staizen/stencil-workers (webpack 4 for now). After you install deps, when you run To enable the workaround (as described in my original post above), uncomment the code in |
Ok, I have added a webpack 5 example as well. The result was surprising here: 1.
|
Added Rollup example to the repo (with workarounds in rollup.config.js). 1. Need to copy worker files to dist manuallySimilar to Webpack 4, Rollup is not able to determine that To fix that, we need to introduce 2. Dynamic imports in Rollup are weird...When using To stop that from happening, I switched to using a dynamic import for the loader, which will preserve it as its own file, but it introduces its own set of problems:
When lazy loading, need to use Rollup only supports static strings for dynamic imports. The stencil ESM bundle uses template literals to load entry files, which are only supported in webpack, but not rollup (the code even has webpack "magic comments"). return import(
/* webpackInclude: /\.entry\.js$/ */
/* webpackExclude: /\.system\.entry\.js$/ */
/* webpackMode: "lazy" */
`./${bundleId}.entry.js${''}`).then((importedModule) => {
{
cmpModules.set(bundleId, importedModule);
}
return importedModule[exportName];
}, consoleError); To fix this, we need to use |
(ahem - or give this PR a +1 :D - ahem) |
@johnjenkins once again to the rescue :O |
I have a similar problem at a different point while loading Ionic (react) in a Meteor project. Like @theo-staizen said, removing that line fixes the issue for me. |
@rwaskiewicz thank you for re-opening the ticket. I have spent the last couple of days updating my demo repo and testing all bundlers I think are relevant today. TL;DR:
|
just chiming in to say, I've found for vite, if you remove your stencil lib from vite's optimisation, things should work as expected - dev or otherwise. e.g.
|
I have a problem related to How stencil bundles web workers. Every time I adjust something in the workers the bundler does not refresh the js chunk file name and that causes the old file to be loaded as it is cached in browser. As a result as long as the cache lives my changes are not reflecting. I thought maybe it is related to how Stencil loads the worker files in the bundle: |
Stencil version:
I'm submitting a:
[x] bug report
[] feature request
Current behavior:
I run into a couple of problems involving web workers and webpack yesterday. This was a react app and they were consuming the react version of our lib (built using
@stencil/react-output-target
), but I think the problems I am describing would happen for any webpack app.The issues are due to the way stencil compiles
.worker.js
files and hardcodes the filename of the generated worker file and for usingimport.meta.url
:import.meta.url
. Workaround for now was to usecjs
bundle instead ofesm
bundle.flags.worker-20711652.js
is a file they should bundle and make available. We had to add acopy-webpack-plugin
in our build to move*.worker-*.js
files fromnode_modules/my-stencil-package/dist/cjs
and into our webpack's output directory so that the URL generated by the line above, is available.It seems a bit problematic, having to resort to these "hacks" to make this code work with bundlers. So I was wondering if there is an improvement to be made here, where stencil can use esm dynamic imports to load the contents of the file, instead of dynamically creating a url, using something like
rollup-plugin-bundle-imports
. That way bundlers will treat it as any other import and make sure the file is available in the bundle.Expected behavior:
Web workers should work transparently when importing the stencil bundle via webpack or other bundlers.
Steps to reproduce:
(You can also checkout this repo https://github.com/theo-staizen/stencil-workers)
Other information:
The text was updated successfully, but these errors were encountered: