-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[4.0.0-rc.1] Javascript_asset_tag is broken #1835
Comments
Made a new release, please give it a try 🙏 |
It working now. Thanks. |
great, thanks @seuros |
Thanks @gauravtiwari ! Unfortunately there is something not right yet. I use the following packs:
I include = javascript_pack_tag 'platform'
...
= javascript_pack_tag 'tenant', defer: true In version The problem is that in the final HTML the <script src="/packs/vendor-c74fedd1b41bbb546647.chunk.js"></script>
<script src="/packs/platform-75df7bfe6d1333d19e71.js"></script>
...
<script src="/packs/vendor-c74fedd1b41bbb546647.chunk.js" defer="defer"></script>
<script src="/packs/tenant-218fa49335d9af3f1b19.js" defer="defer"></script> It probably detects the dependency of both |
@Zyphrax Thanks, I noticed the problem. I didn't realize this might have implications on The idea with this was to include in runtime chunks so you don't have to especially include them or add an option, which one might easily forget. Perhaps, we only check for runtime chunks and include them and leave the rest out so you can include them manually? |
Could a simple solution here be to store the list of non-entry point javascript files that have been loaded, and skip adding the If the case above, this would add the |
@renchap Yep, it's possible but I think it's best to exclude anything that's not related to a pack and one can include that manually, for ex: vendor can be included anywhere, under the Wrote a fix, will make a PR in a bit. |
I am going to take a look at this properly tomorrow if anyone has ideas feel free to make a PR. |
I am not sure why you do not want to do it automatically, this could make it much easier for people. Or maybe with a setting to disable this behaviour? |
Mainly, just to make things easier if it's a runtime chunk. It's quite easy to forget one if people are using |
I agree that it is a good idea to automatically include dependent packs, and my proposal is to only add something so a dependent pack only get included once per page. With an optional setting to disable this automatic behaviour if people want to do it manually for whatever reason. |
I also think that if a stylesheet exists for a pack it should be included automatically in the HTML as well, but this may be more complex (as stylesheets should be in |
I really like the functionality that (dependency) packs are automatically included in the page. This indeed makes it a lot easier to handle the runtime chunk, but also the scenario of Maybe calls to The That would make the following scenarios possible: Fully automatic
Semi automatic
Manual
I would keep stylesheets separate from the javascripts. A |
Thanks for your input @Zyphrax and @renchap, some great ideas there. I will put together a PR later this week. If someone wants to work on this please leave a comment here. Hopefully, we will have webpacker 4 stable released just around Christmas time 🎉 🎅 Thanks, everyone for being patient and helpful 🙏 |
I would +1 on what @Zyphrax said, automatic dependency inclusion could avoid a lot of headaches, knowing that webpack changes extracted chunks name often (if not overridden) and have different settings for |
@gauravtiwari Ideally, with the way |
@jakeNiemiec My configuration is the same as the second example on Webpack’s splitChunks page. It gobbles up all vendor libraries into one big pack, which is fine for my project. @gauravtiwari Thank you for all the great work! |
Temporary workaround for people that have duplicate includes: / Don't include dependencies, write only the platform script tag
= javascript_include_tag asset_pack_path('platform.js')
/ Include dependencies, write script tags for vendor and tenant
= javascript_pack_tag 'tenant' |
Please give new RC a try. |
@Zyphrax duplicate includes shouldn't be a problem right? The browser has the content cached already? Do you think that chunks with side-effects ( |
@jakeNiemiec Duplicate includes causes the JavaScript code to be executed twice (or as many times as the script is included). It is a waste of performance and it could indeed have side-effects on older libraries that depend on code being loaded in a specific order or utility frameworks like error handlers. @gauravtiwari Thank you! I'm going to give it a spin! |
@gauravtiwari Works great, thank you! 🎉 |
My point is that you should always treat vendor libs (especially older libs) as "effectful imports". Splitting your app into multiple packs, just to load them on the same page is the waste of performance and compile time. Webpack is assuming that those different entrypoints are on exclusive pages (hence the duplication). take: This would be the proper way to make the entrypoint: // calendarMapPack.js
import 'calendar';
import 'map';
// OR async in parallel
import(/* webpackMode: "lazy" */
/* webpackChunkName: "calendar" */
'calendar');
import(/* webpackMode: "lazy" */
/* webpackChunkName: "map" */
'map'); Any sub-files that you need to load would be within the single entrypoint. With the way it is now, you are fighting and negating any tree-shaking. Plus, you will start getting issues with a lot of weird edge cases (already happening). Take a look at some examples of this: webpack/webpack#6571 (comment) |
I've upgraded from
4.0.0-pre.3
to4.0.0-rc.1
and now I get a really strange error in my application.slim:This errors seems to be caused by this call in my project:
app/views/layout/application.slim
= javascript_pack_tag 'vendor'
It seems that
javascript_pack_tag
generates a hash and is incorrectly converted to a Rails include tag. It seems to think that the hash is thesrc
.Edit: It might have something to do with my splitChunks configuration
This was working fine in
4.0.0-pre.3
, but now something goes wrong in manifest.rb - lookup.Configurations with
cacheGroups
no longer work?The text was updated successfully, but these errors were encountered: