fix(helpers): keep falsy but defined values in fillTemplate - #12609
Arunendra21 wants to merge 1 commit into
Conversation
fillTemplate replaced each ${var} with `templateVars[match] || ''`,
which also dropped values that are defined but falsy, such as the
number 0 or the boolean false. For example fillTemplate('${n}', {n: 0})
returned an empty string instead of '0'.
This is noticeable in Pagination, where PaginationOptionsMenu passes
numeric firstIndex, lastIndex and itemCount into a string toggle
template. With an empty data set (itemCount of 0) the '0' was silently
dropped from the toggle text.
Use the nullish coalescing operator so only null or undefined values
(for example a missing key) fall back to an empty string, while 0 and
false are kept.
Co-authored-by: eeshsaxena <eeshsaxena@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Walkthrough
ChangesfillTemplate behavior
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Friendly ping on this one — it's a small, self-contained bug fix and has been open for a few weeks. Happy to rebase or make any changes if a maintainer has a chance to take a look. Thanks! |
What: Fixes a bug in the
fillTemplatehelper (packages/react-core/src/helpers/util.ts).fillTemplatereplaced each${var}withtemplateVars[match] || '', which also dropped values that are defined but falsy, such as the number0or the booleanfalse. For example:This shows up in Pagination.
PaginationOptionsMenupasses numericfirstIndex,lastIndexanditemCountinto a string toggle template, so an empty data set (itemCountof0) silently dropped the0from the rendered toggle text (for example1 - 0 ofinstead of1 - 0 of 0).The fix switches
||to the nullish coalescing operator??, so onlynullorundefined(for example a missing key) fall back to an empty string, while0andfalseare preserved. Missing keys still resolve to an empty string, so existing behavior is unchanged.Additional issues: none. This was found while reading the helper code.
Testing: added unit tests in
util.test.tscovering0,false, empty string, and missing keys. The existingfillTemplateinterpolation test still passes.Summary by CodeRabbit
Bug Fixes
0,false, and empty strings.Tests