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

fix: disable load manifest in dev #1711

Merged
merged 3 commits into from Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-books-flash.md
@@ -0,0 +1,5 @@
---
'preact-cli': patch
---

Fix ensures that the load-manifest is only attempted to be built in prod. It serves no use in dev (as preloading is limited to prod) and can create a race condition when used alongside HMR.
3 changes: 2 additions & 1 deletion packages/cli/lib/lib/webpack/create-load-manifest.js
@@ -1,4 +1,5 @@
module.exports = (assets, namedChunkGroups) => {
module.exports = (assets, namedChunkGroups, isProd) => {
if (!isProd) return {};
/**
* This is a mapping of generic/pre-build filenames to their postbuild output
*
Expand Down
6 changes: 5 additions & 1 deletion packages/cli/lib/lib/webpack/push-manifest.js
Expand Up @@ -2,6 +2,9 @@ const webpack = require('webpack');
const createLoadManifest = require('./create-load-manifest');

module.exports = class PushManifestPlugin {
constructor(isProd) {
this.isProd = isProd;
}
apply(compiler) {
compiler.hooks.emit.tap(
{
Expand All @@ -11,7 +14,8 @@ module.exports = class PushManifestPlugin {
compilation => {
const manifest = createLoadManifest(
compilation.assets,
compilation.namedChunkGroups
compilation.namedChunkGroups,
this.isProd
);

let output = JSON.stringify(manifest);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/lib/webpack/render-html-plugin.js
Expand Up @@ -89,7 +89,7 @@ module.exports = async function (config) {
if (assets['push-manifest.json']) {
return JSON.parse(assets['push-manifest.json'].source());
}
return createLoadManifest(assets, namedChunkGroups);
return createLoadManifest(assets, namedChunkGroups, config.isProd);
},
config,
url,
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/lib/lib/webpack/webpack-client-config.js
Expand Up @@ -146,7 +146,7 @@ async function clientConfig(env) {
'process.env.ADD_SW': env.sw,
'process.env.PRERENDER': env.prerender,
}),
new PushManifestPlugin(),
new PushManifestPlugin(env.isProd),
Copy link
Member Author

Choose a reason for hiding this comment

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

Moving this into the prod config seems like a better move at first glance, but renderHTMLPLugin depends on it being ran first so we need to keep it here.

...(await renderHTMLPlugin(env)),
...getBabelEsmPlugin(env),
copyPatterns.length !== 0 &&
Expand Down Expand Up @@ -331,7 +331,7 @@ function isDev(env) {
].filter(Boolean),

devServer: {
hot: true,
hot: env.refresh,
liveReload: !env.refresh,
compress: true,
devMiddleware: {
Expand Down