Commit ec6a2a3b authored by Mark Florian's avatar Mark Florian

Fix monaco chunk errors during development

Sometimes, when trying to view a page which prefetches monaco, like
viewing a snippet or the WebIDE, this error would be displayed:

    Can’t find entry point ‘monaco’ in webpack manifest

This was happening because:

1. Incremental webpack compilation is enabled by default, meaning that
   only a subset of all possible chunks are compiled.
2. The monaco chunk is only split out if two or more chunks depend
   on it. (See [minChunks]).

So, if the user doesn't have two or more chunks in their webpack
compilation history (likely, especially on fresh installs), the monaco
chunk isn't split out, so it's not listed as a chunk in the manifest,
causing the prefetch to fail.

The fix is to ignore AssetMissingErrors in the prefetch function when
the webpack dev server is being used in development or test
environments, where incremental compilation may be enabled. This is done
to mitigate this problem occuring due to potentially other chunks not
getting split out for a similar reason.

An earlier iteration of this fix also reduced
`optimization.splitChunks.cacheGroups.monaco.minChunks` option in
`webpack.config.js` from 2 to 1, to make sure the monaco chunk was
always produced. However, that had the side-effect of inflating the size
of various entry points, so was reverted. See the [MR] for more details.

[MR]: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/78202
parent 4844ca81
......@@ -25,6 +25,10 @@ module WebpackHelper
else
preload_link_tag(path, options)
end
rescue Gitlab::Webpack::Manifest::AssetMissingError
# In development/test, incremental compilation may be enabled, meaning not
# all chunks may be available/split out
raise unless Gitlab.dev_or_test_env?
end
def webpack_controller_bundle_tags
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment