How is webpack js chunk hash determined?
Unanswered
Pacific sandlance posted this in #help-forum
Pacific sandlanceOP
I am seeing an issue where the hash isn't changing even though the content of the build has changed, and now the static file is referencing incorrect js file names.
12 Replies
Pacific sandlanceOP
So anyone that had visited already has a cached static asset in their browser forever referencing old assets that no longer exist. Feel like the webpack chunk filename should've changed on the latest build, but it doesn't - and I get the same filename when building locally.
Pacific sandlanceOP
How is a file with
public, max-age=31536000, immutable
allowed to have its content change, but not its filename change? This seems very broken.Pacific sandlanceOP
Anyone?
Pacific sandlanceOP
Alright narrowed it down. I updated next from 15.1.6 to 15.3.1.
Something between those versions changed the content of compiled js chunks. The chunk filename is correctly changing, since its content changed.
But what isn't changing is the webpack-[chunkhash].js filename, even though the CONTENT has changed. It's referencing the new chunk names.
Something between those versions changed the content of compiled js chunks. The chunk filename is correctly changing, since its content changed.
But what isn't changing is the webpack-[chunkhash].js filename, even though the CONTENT has changed. It's referencing the new chunk names.
Pacific sandlanceOP
Narrowed it down further. On 15.2.5, here are the built chunks, everything is working fine:
But on 15.3.0:
webpack-fc8 is referencing the filename of reactPlayerYouTube which has changed, and the content of the webpack file has changed, but the filename has not changed.
This means people that have already visited the site have an immutable, long-cached webpack.js file referencing deleted content.
This means people that have already visited the site have an immutable, long-cached webpack.js file referencing deleted content.
This shouldn't be possible.
Pacific sandlanceOP
Finally, I think it's because dynamically loaded chunks (which reactPlayerYouTube is) use
So I can only assume that
[contenthash]
to generate their filenames, whereas the non-dynamically loaded chunks use [chunkhash]
.So I can only assume that
[contenthash]
is determined after webpack compilation of a file (runs against the minified / uglified / otherwise transformed file) whereas [chunkhash]
is determined by the precompiled content of the referenced chunks? I have no idea.Pacific sandlanceOP
The actual source code of the ReactPlayerYouTube component has not changed, only the compiled chunk because of minifier differences between next.js versions.
Interestingly only app router uses
chunkhash
:appDir ? '-[chunkhash]' : '-[contenthash]'
I wonder why they switched from
contenthash
, which would solve this.