TanStack / TanStack/devtools

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

Aperta
#435 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
TypeScript
Stelle
499
Fork
100
Merge medio
1g 17h
PR unite (30g)
4

Descrizione

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+

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia da packages/devtools-vite/src/virtual-console.ts e ispeziona l'handler lato browser che chiama logMethod.apply con il prefisso del server e transformedArgs. Riproduci il problema con un log di richiesta Nitro in un'app TanStack Start usando il plugin Vite di devtools. Il lavoro è completato quando i segnaposto in stile printf vengono sostituiti correttamente nella console del browser invece di apparire come token letterali.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript, vite
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Specificata chiaramente
Idoneità per principianti
72/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.