Server log pipe drops printf-style format substitution, leaks raw `%s` into browser console
还没有人认领这个 Issue。
- 主要语言
- TypeScript
- 星标
- 499
- 派生
- 100
- 平均合并
- 1 天 17 小时
- 30 天内合并 PR
- 4
描述
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.formaton 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+
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 packages/devtools-vite/src/virtual-console.ts 开始,检查调用 logMethod.apply 并传入 server prefix 和 transformedArgs 的浏览器端 handler。使用 devtools Vite plugin 在 TanStack Start 应用中通过 Nitro request log 重现该问题。完成标准是 printf 风格的占位符在 browser console 中被正确替换,而不是显示为字面量 token。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- typescript, vite
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100