Files
bun.sh/src/bundler/linker_context/postProcessHTMLChunk.zig
Claude Bot ee31d232c2 fix(bundler): HTML entrypoint hash now updates when dependencies change
Previously, HTML chunk hashes were not recomputed when their JS/CSS dependencies
changed because the isolated_hash computation for HTML chunks didn't account for
the hashes of their dependencies. This caused browsers to cache stale HTML files
that referenced old asset URLs, leading to 404 errors.

The fix:
1. Added generateIsolatedHashWithChunks() that accepts a chunks array
2. HTML chunks now include their JS/CSS dependencies' hashes in their own hash
3. Process non-HTML chunks before HTML chunks to ensure dependency hashes are computed

This ensures HTML files get new hashes when their dependencies change, preventing
browser caching issues reported in https://github.com/NDC-Tourney/stream-overlay/pull/40

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-19 09:22:12 +00:00

36 lines
1.0 KiB
Zig

pub fn postProcessHTMLChunk(ctx: GenerateChunkCtx, worker: *ThreadPool.Worker, chunk: *Chunk) !void {
// This is where we split output into pieces
const c = ctx.c;
var j = StringJoiner{
.allocator = worker.allocator,
.watcher = .{
.input = chunk.unique_key,
},
};
const compile_results = chunk.compile_results_for_chunk;
for (compile_results) |compile_result| {
j.push(compile_result.code(), bun.default_allocator);
}
j.ensureNewlineAtEnd();
chunk.intermediate_output = c.breakOutputIntoPieces(
worker.allocator,
&j,
@as(u32, @truncate(ctx.chunks.len)),
) catch |err| bun.handleOom(err);
chunk.isolated_hash = c.generateIsolatedHashWithChunks(chunk, ctx.chunks);
}
const bun = @import("bun");
const StringJoiner = bun.StringJoiner;
const Chunk = bun.bundle_v2.Chunk;
const ThreadPool = bun.bundle_v2.ThreadPool;
const LinkerContext = bun.bundle_v2.LinkerContext;
const GenerateChunkCtx = bun.bundle_v2.LinkerContext.GenerateChunkCtx;