[hash] does not change when output.sourcemap changes the final chunk content
Rollup Version
4.62.5
Operating System (or Browser)
macOS/Chrome 151
Node Version (if applicable)
No response
Link To Reproduction
Expected Behaviour
Changing output.sourcemap from true to false changes the final emitted js content because the sourceMappingURL comment is removed. I would expect the chunk [hash] to change when the final emitted chunk content changes
Actual Behaviour
A minimal reproduction is provided in the StackBlitz link above. It explains that changing only output.sourcemap changes the emitted JavaScript content but does not change the [hash] in the chunk filename.
For example when building with: output: { chunkFileNames: 'chunks/[name]-[hash].js', sourcemap: true }
Rollup generates, for example: chunks/chunk-ABC123.js chunks/chunk-ABC123.js.map
and the emitted JavaScript contains: //# sourceMappingURL=chunk-ABC123.js.map
When I then change only: sourcemap: false
Rollup correctly regenerates the JavaScript and removes the sourceMappingURL comment.
However, the generated filename remains: chunks/chunk-ABC123.js
So the final content has changed, but the [hash] remains the same.
This becomes a problem in our system because we rely on Rollup's [hash] in the filename as a cache-busting mechanism for browser-cached chunks.
After the second build, the browser still have the previous chunks/chunk-ABC123.js cached. Which contains: //# sourceMappingURL=chunk-ABC123.js.map
As a result, React DevTools continues attempting to fetch the .map files, even though the .map file no longer exists on disk, resulting in repeated 404 requests.
So the issue is that changing sourcemap changes the final emitted JavaScript content, but does not change the [hash] in the chunk filename and because we rely on that hash as a browser cache-busting mechanism, the browser still use the previous version of the chunk.
Source: rollup/rollup