sourcemap inject/upload doesn't recognize a debug ID snippet minified to template literals and shifts Vite 8 chunks one line

Đang mở
#2,248 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
Nửa ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript, node.js, typescript, vite
Lĩnh vực
build-system, cli, devtools

Hướng nghiên cứu

Start with DEBUGID_REGISTRATION_RE and the bracketed-key regex in packages/cli/src/lib/sourcemap/debug-id.ts, which only accept " or ' as delimiters. Run the reproduction in the issue against a chunk using backtick-quoted registrations; inject --dry-run should report modified 1 today. Done when that case reports skipped 1 with the same delimiter-matching behavior as double quotes, and tests cover both the plain and bracketed forms.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Environment
  • sentry 0.49.0, via @sentry/vite-plugin / @sentry/bundler-plugins 11.12.0
  • Vite 8.3.8 (Rolldown, Oxc minifier), build.sourcemap: true
  • The same check is on main at cc90ca1e
Summary

Every frame from a Vite 8 build resolves one generated line off in Sentry.

The bundler plugin injects its debug ID snippet in renderChunk, and Vite 8's minifier then rewrites the snippet's string literals as template literals:

e._sentryDebugIds[t]=`4f39e3c4-c308-4c2e-8975-3241d12fbeef`,e._sentryDebugIdIdentifier=`sentry-dbid-4f39e3c4-c308-4c2e-8975-3241d12fbeef`

The plugin then uploads with sourcemap.upload, which runs inject first. DEBUGID_REGISTRATION_RE only matches a value quoted with " or ':

...\\s*=\\s*(["'])(${DEBUGID_PATTERN})\\1

so the CLI doesn't see the existing registration, prepends a second snippet and adds an empty line to the map's mappings. The uploaded copy and its map agree with each other, but the deployed file doesn't have that extra line, so Sentry resolves every frame one line too high.

This is the same mechanism as #2189, with a different trigger: #2190 taught the check Turbopack's _debugIds form, but it still requires quotes.

Reproduction
dir=$(mktemp -d)
cat > "$dir/chunk.js" <<'EOF'
const a=1;
(()=>{try{let e=globalThis,t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`4f39e3c4-c308-4c2e-8975-3241d12fbeef`,e._sentryDebugIdIdentifier=`sentry-dbid-4f39e3c4-c308-4c2e-8975-3241d12fbeef`)}catch{}})();console.log(a);
//# sourceMappingURL=chunk.js.map
//# debugId=4f39e3c4-c308-4c2e-8975-3241d12fbeef
EOF
echo '{"version":3,"sources":["a.ts"],"names":[],"mappings":"AAAA;AACA","debugId":"4f39e3c4-c308-4c2e-8975-3241d12fbeef"}' > "$dir/chunk.js.map"
npx [email protected] sourcemap inject --dry-run --json "$dir"

Expected: "modified": 0, "skipped": 1, as with the same file using " quotes.
Actual: "modified": 1, "skipped": 0.

Suggested fix

Accept a backtick in the quote class:

-  ...\\s*=\\s*(["'])(${DEBUGID_PATTERN})\\1`,
+  ...\\s*=\\s*(["'\`])(${DEBUGID_PATTERN})\\1`,

The backreference still requires matching delimiters. The bracketed key form (\\[\\s*["']${DEBUGID_REGISTRY}["']\\s*\\]) probably wants the same, since a minifier can emit e[`_sentryDebugIds`].

We're working around it with a pnpm patch making exactly this change. With it, all of our uploaded chunks match the deployed files except for the appended //# debugId= comment, and their maps are unchanged.

Ngôn ngữ chính
TypeScript
Star
961
Fork
179
Merge trung bình
15 giờ 33 phút
Pull request đã merge (30 ngày)
476

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của getsentry/toolkit

Tất cả issue của getsentry/toolkit

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.