TanStack / TanStack/devtools

Server log pipe drops printf-style format substitution, leaks raw `%s` into browser console

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

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

Ngôn ngữ chính
TypeScript
Star
499
Fork
100
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
4

Mô tả

When server-side logs that use printf-style formatting (e.g. Nitro's request logger calling console.log('%s - %s info GET %s %d in %dms', ts, level, method, status, ms)) are piped to the browser via the virtual-console SSE bridge, the format substitution is lost and the literal %s tokens appear in the browser console.

Example output in browser:

[Server] %s - %s info GET /build-version 200 in 1ms

Cause

In packages/devtools-vite/src/virtual-console.ts, the browser-side handler reconstructs the call as:

var prefix = '%c[Server]%c';
logMethod.apply(console, [prefix, prefixStyle, resetStyle].concat(transformedArgs));

The browser console only treats the first argument as a format string. Since the prefix '%c[Server]%c' is now in position 0, the original server-side format string (which is at transformedArgs[0]) is no longer interpreted — its %s tokens print literally and the remaining args are appended as separate values rather than substituted.

Reproduction

Any TanStack Start app with devtools() in the Vite plugins. Hit any route while the dev server is running; the Nitro request log lands in the browser console with literal %s.

Suggested fix

Either:

  • (a) Pre-format the server args with util.format on the server before serializing, so the browser receives a single already-formatted string; or
  • (b) On the browser side, if transformedArgs[0] is a string containing format specifiers, merge it into the prefix format string (e.g. '%c[Server]%c ' + transformedArgs[0]) and shift the remaining args accordingly.

Environment

  • @tanstack/devtools-vite@0.6.0
  • Vite 8
  • TanStack Start
  • Node 18+

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

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.

Hướng nghiên cứu

Bắt đầu trong packages/devtools-vite/src/virtual-console.ts và kiểm tra handler phía trình duyệt gọi logMethod.apply với server prefix và transformedArgs. Tái hiện issue bằng một Nitro request log trong một ứng dụng TanStack Start sử dụng devtools Vite plugin. Được xem là hoàn thành khi các placeholder theo kiểu printf được thay thế chính xác trong browser console thay vì hiển thị dưới dạng các token nguyên văn.

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

Đánh giá

Công nghệ
typescript, vite
Lĩnh vực
devtools
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

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.