Server log pipe drops printf-style format substitution, leaks raw `%s` into browser console
Personne n'a encore pris cette issue.
- Langage dominant
- TypeScript
- Étoiles
- 499
- Forks
- 100
- Merge moyen
- 1 j 17 h
- PR mergées (30 j)
- 4
Description
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+
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans packages/devtools-vite/src/virtual-console.ts et examinez le handler côté navigateur qui appelle logMethod.apply avec le préfixe du serveur et transformedArgs. Reproduisez le problème avec un log de requête Nitro dans une application TanStack Start utilisant le plugin Vite de devtools. C'est terminé lorsque les marqueurs de position de style printf sont correctement remplacés dans la console du navigateur au lieu d'apparaître comme des tokens littéraux.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- typescript, vite
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 3/5
- Temps estimé
- 1-2 jours
- Activité
- Calme
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 72/100