Skip to content

fix: preserve explicit zero in numeric config defaults and order totals#89

Merged
paulobernardoaf merged 1 commit intomainfrom
fix/preserve-zero-numeric-defaults
Apr 17, 2026
Merged

fix: preserve explicit zero in numeric config defaults and order totals#89
paulobernardoaf merged 1 commit intomainfrom
fix/preserve-zero-numeric-defaults

Conversation

@paulobernardoaf
Copy link
Copy Markdown
Contributor

Summary

Replace || fallbacks with ?? in three places where 0 was being silently overridden by the default, because JavaScript's logical OR treats 0 as falsy.

  • src/standalone.jsxmapConfig
    • renderPercentage: passing 0 (intended to hide the widget) was being converted to 100, so the webchat always rendered. Now 0 reaches the service and shouldRender correctly resolves to false.
    • tooltipDelay: passing 0 was being converted to 500, so there was no way to show the tooltip immediately. Now 0 is respected.
  • src/components/Messages/MessageOrder.jsx
    • The order total reducer counted product items with quantity: 0 as 1. It now contributes 0, while still defaulting missing/undefined quantities to 1.

Root cause

All three cases relied on value || default, which falls back on any falsy value including 0. Nullish coalescing (value ?? default) only falls back on null/undefined, preserving explicit zeros.

Test plan

  • Initialize the widget with renderPercentage: 0 → widget does not render.
  • Initialize the widget with renderPercentage: 100 (or omitted) → widget renders as before.
  • Initialize the widget with tooltipDelay: 0 and a tooltipMessage → tooltip appears immediately.
  • Initialize the widget with tooltipDelay omitted → tooltip still defaults to 500 ms.
  • Render MessageOrder with a product_items entry where quantity: 0 → total is 0.
  • Render MessageOrder with a product_items entry where quantity is missing → total defaults to 1 per item (existing behavior).

Made with Cursor

Replace `||` fallbacks with `??` so callers passing `0` are not silently
overridden by the default value:

- `standalone.jsx` (`mapConfig`):
  - `renderPercentage`: `0` now reaches the service so the widget can be
    hidden on purpose instead of always rendering
  - `tooltipDelay`: `0` now means "show immediately" instead of `500`
- `MessageOrder`: product items with `quantity: 0` no longer contribute
  `1` to the total item count

Made-with: Cursor
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 66.14%. Comparing base (b014892) to head (f221de3).

Files with missing lines Patch % Lines
src/standalone.jsx 0.00% 2 Missing ⚠️
src/components/Messages/MessageOrder.jsx 0.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #89   +/-   ##
=======================================
  Coverage   66.14%   66.14%           
=======================================
  Files          71       71           
  Lines        3096     3096           
  Branches      837      854   +17     
=======================================
  Hits         2048     2048           
+ Misses       1021     1020    -1     
- Partials       27       28    +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 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.

@paulobernardoaf paulobernardoaf merged commit a5fc0b7 into main Apr 17, 2026
2 checks passed
@paulobernardoaf paulobernardoaf deleted the fix/preserve-zero-numeric-defaults branch April 17, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants