You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
util: styleText() fast path ignores changes to util.inspect.colors #67980
v28.0.0-pre (main @ 9873287), also reproduced on v26.12.1
Platform
Darwin 27.2.0 arm64 (macOS, Apple Silicon)
Subsystem
util
What steps will reproduce the bug?
constutil=require('node:util');// First call with validateStream: false builds the internal style cacheutil.styleText('red','x',{validateStream: false});// Customize a color, as documented in "Customizing util.inspect colors"util.inspect.colors.red=[91,39];consta=util.styleText('red','x',{validateStream: false});constb=util.styleText(['red'],'x',{validateStream: false});console.log(JSON.stringify(a));console.log(JSON.stringify(b));console.log(a===b);
How often does it reproduce? Is there a required condition?
Always. It only happens if styleText() was called with validateStream: false
before util.inspect.colors was modified. If the first call is removed, both
results are the same.
What is the expected behavior? Why is that the expected behavior?
Both calls should return the same string using the updated color: "\u001b[91mx\u001b[39m"
The docs say util.inspect.colors can be customized globally, and the slow
path and array format already pick up the change.
Traced this to lib/util.js: getStyleCache() (lines 144-156) builds the style cache from util.inspect.colors once and never invalidates it, so the fast path at lines 250-258 keeps serving the old codes after a color is customized. The slow path reads the live colors, which is why the array format disagreed.
Fix in #67989: the fast path now refreshes the cached entry for the requested format from the live colors on each call, and drops the entry if the color was removed so the slow path throws as before. Added a regression test covering the repro from this issue. Verified the fix logic locally against the repro and edge cases (in-place mutation, new color, deleted color); full suite needs CI since there is no node build on this machine.
Activity
bunnysayzz commentedon Dec 3, 2026
Traced this to lib/util.js: getStyleCache() (lines 144-156) builds the style cache from util.inspect.colors once and never invalidates it, so the fast path at lines 250-258 keeps serving the old codes after a color is customized. The slow path reads the live colors, which is why the array format disagreed.
Fix in #67989: the fast path now refreshes the cached entry for the requested format from the live colors on each call, and drops the entry if the color was removed so the slow path throws as before. Added a regression test covering the repro from this issue. Verified the fix logic locally against the repro and edge cases (in-place mutation, new color, deleted color); full suite needs CI since there is no node build on this machine.