Skip to content

util: refresh styleText() fast-path cache when inspect colors change - #67989

Open
bunnysayzz wants to merge 1 commit into
nodejs:mainfrom
bunnysayzz:fix/styletext-stale-cache-67980
Open

bunnysayzz wants to merge 1 commit into
nodejs:mainfrom
bunnysayzz:fix/styletext-stale-cache-67980

Conversation

@bunnysayzz

Copy link
Copy Markdown
Contributor

Fixes #67980

The styleText() fast path builds a cache of util.inspect.colors once in getStyleCache() and never invalidates it, so changing a color after the first call had no effect there, while the slow path and the array format picked it up. This refreshes the cached entry for the requested format from the live colors on each call, and drops the entry when the color was removed so the slow path throws as before.

Verified the fix logic against the issue repro plus edge cases (in-place mutation, new color, deleted color, bold/dim keepClose) with a local harness using the patched functions; the new test fails on the current code and passes with the fix. I could not run the full test suite here since there is no node build on this machine, CI will confirm.

Note: I used an AI assistant to help draft this change.

The styleText() fast path builds a cache of util.inspect.colors once
in getStyleCache() and never invalidates it, so customizing a color
after the first call had no effect on the fast path while the slow
path and array format picked it up. Refresh the cached entry for the
requested format from the live colors on each call, and drop the
entry when the color was removed so the slow path throws as before.

Fixes: nodejs#67980
Signed-off-by: bunnysayzz <stfuazzo@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Dec 3, 2026
@codecov

codecov Bot commented Dec 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.56%. Comparing base (6545c34) to head (93a5094).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #67989      +/-   ##
==========================================
- Coverage   90.58%   90.56%   -0.03%     
==========================================
  Files         802      802              
  Lines      286955   286971      +16     
  Branches    55404    55418      +14     
==========================================
- Hits       259942   259882      -60     
- Misses      17115    17165      +50     
- Partials     9898     9924      +26     
Files with missing lines Coverage Δ
lib/util.js 100.00% <100.00%> (ø)

... and 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util: styleText() fast path ignores changes to util.inspect.colors

2 participants