diff --git a/src/bake/DevServer/ErrorReportRequest.zig b/src/bake/DevServer/ErrorReportRequest.zig index a71bfdce6d..766872d841 100644 --- a/src/bake/DevServer/ErrorReportRequest.zig +++ b/src/bake/DevServer/ErrorReportRequest.zig @@ -124,9 +124,21 @@ pub fn runWithBody(ctx: *ErrorReportRequest, body: []const u8, r: AnyResponse) ! } const result: *const SourceMapStore.GetResult = &(gop.value_ptr.* orelse continue); - // When before the first generated line, remap to the HMR runtime + // When before the first generated line, remap to the HMR runtime. + // + // Reminder that the HMR runtime is *not* sourcemapped. And appears + // first in the bundle. This means that the mappings usually looks like + // this: + // + // AAAA;;;;;;;;;;;ICGA,qCAA4B; + // ^ ^ generated_mappings[1], actual code + // ^ + // ^ generated_mappings[0], we always start it with this + // + // So we can know if the frame is inside the HMR runtime if + // `frame.position.line < generated_mappings[1].lines`. const generated_mappings = result.mappings.generated(); - if (frame.position.line.oneBased() < generated_mappings[1].lines) { + if (generated_mappings.len <= 1 or frame.position.line.zeroBased() < generated_mappings[1].lines) { frame.source_url = .init(runtime_name); // matches value in source map frame.position = .invalid; continue;