Skip to content

fix(rate-widget): cap maxCount to protect property pane, layout sizing, and render (#14833) - #42081

Open
buyua9 wants to merge 2 commits into
appsmithorg:releasefrom
buyua9:fix/rating-widget-maxcount-three-surfaces
Open

fix(rate-widget): cap maxCount to protect property pane, layout sizing, and render (#14833)#42081
buyua9 wants to merge 2 commits into
appsmithorg:releasefrom
buyua9:fix/rating-widget-maxcount-three-surfaces

Conversation

@buyua9

@buyua9 buyua9 commented Aug 3, 2026

Copy link
Copy Markdown

Summary

  • cap the Rating widget maxCount to the safe 1–100 range
  • apply the same normalized value to property-pane validation, auto-layout sizing, anvil sizing, and render output
  • add focused regression coverage for overflow, invalid, and string inputs

Closes #14833. Related: #15586. PR #41897 was stale-closed after covering only the property-pane/render surfaces; this patch also closes the layout-sizing gap.

Validation

  • standalone helper replay: 26/26 assertions
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes
    • Improved Rating widget handling for invalid, fractional, zero, and excessive maximum-rating values.
    • Maximum ratings are now safely limited to 100, with a default of 5 when values are invalid.
    • Updated widget sizing and display to prevent oversized layouts or excessive rating indicators.
    • Property settings now enforce a valid maximum-rating range from 1 to 100.
    • Numeric text values are handled safely when configuring the maximum rating.

…g, and render (appsmithorg#14833)

The Rating widget's maxCount property had no upper bound. A value like
1_000_000 (typed directly, or supplied by a data binding on page load)
crashed the browser with 'Aw, snap!' because the widget rendered one DOM
star node per unit of maxCount and asked the layout engine to honour a
minWidth proportional to maxCount.

The previous attempt (PR appsmithorg#41897, closed for inactivity on 2026-06-28)
capped the property pane and the render path but left the two
auto-layout sizing surfaces untouched. With a binding returning >= 1_000
the layout engine still produced a minWidth of >= 25_000 px and the
browser could crash via the layout box, not via the star render.

This commit caps the value uniformly across all three surfaces:

* property pane: ValidationTypes.NUMBER params now include min: 1 and
  max: 100, with an updated helpText that names the allowed range;
* getAutoLayoutConfig: widgetSize[0].configuration now routes
  props.maxCount through getSafeMaxCount before computing minWidth;
* getAnvilConfig: widgetSize now routes props.maxCount through
  getSafeMaxCount before computing minWidth;
* getWidgetView: the value forwarded to <RateComponent> is the clamped
  safeMaxCount, so the render path is defended even if a binding
  changes maxCount after the property-pane validation pass.

The cap and a getSafeMaxCount() helper live in RateWidget/constants.ts
so every consumer of maxCount goes through the same source of truth.
Defaults (DEFAULT_MAX_RATE_COUNT = 5) preserve today's behaviour for
the case where maxCount is missing, non-numeric, or non-positive.

A Jest unit test (constants.test.ts) pins the cap so a future
regression on any of the three surfaces cannot pass CI silently.

Closes appsmithorg#14833
@buyua9
buyua9 requested a review from a team as a code owner August 3, 2026 15:25
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3cb1a0be-c073-4d79-937a-e9359d41c1cf

📥 Commits

Reviewing files that changed from the base of the PR and between 82c6d63 and 2e20e45.

📒 Files selected for processing (2)
  • app/client/src/widgets/RateWidget/constants.test.ts
  • app/client/src/widgets/RateWidget/constants.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/client/src/widgets/RateWidget/constants.test.ts
  • app/client/src/widgets/RateWidget/constants.ts

Walkthrough

The Rating widget adds shared maxCount bounds and sanitization. Layout calculations, property validation, and rendering now use safe values. Unit tests cover valid, invalid, fractional, string, and oversized inputs.

Changes

RateWidget max-count safety

Layer / File(s) Summary
Safe maxCount contract
app/client/src/widgets/RateWidget/constants.ts, app/client/src/widgets/RateWidget/constants.test.ts
Adds MAX_RATE_COUNT, DEFAULT_MAX_RATE_COUNT, and getSafeMaxCount. Tests cover fallback and clamping behavior.
Widget sizing and rendering integration
app/client/src/widgets/RateWidget/widget/index.tsx
Uses sanitized maxCount values for layout sizing and rendering. Property validation enforces values from 1 through MAX_RATE_COUNT.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

Safe counts guide each star,
Large values stay afar.
Bounds guard layout flow,
Tests confirm what they know.
Ratings render bright and clear.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes capping Rating widget maxCount to protect property-pane, layout, and rendering behavior.
Description check ✅ Passed The description explains the motivation, scope, linked issue, regression coverage, and validation; omitted template sections are non-critical.
Linked Issues check ✅ Passed The changes address [#14833] by normalizing large maxCount values across validation, sizing, rendering, and regression tests.
Out of Scope Changes check ✅ Passed All code and test changes support safe maxCount handling and the linked issue objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/client/src/widgets/RateWidget/constants.ts`:
- Around line 40-52: Update getSafeMaxCount in
app/client/src/widgets/RateWidget/constants.ts:40-52 to parse string inputs with
Number() and reject any parsed value that is not an integer, while preserving
the existing positive-range and maximum clamping behavior. Add assertions in
app/client/src/widgets/RateWidget/constants.test.ts:52-56 confirming both 1.5
and "1.5" return DEFAULT_MAX_RATE_COUNT.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 79312e88-a1af-449b-bd46-dafefdb99560

📥 Commits

Reviewing files that changed from the base of the PR and between ec663b7 and 82c6d63.

📒 Files selected for processing (3)
  • app/client/src/widgets/RateWidget/constants.test.ts
  • app/client/src/widgets/RateWidget/constants.ts
  • app/client/src/widgets/RateWidget/widget/index.tsx

Comment thread app/client/src/widgets/RateWidget/constants.ts
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.

[Bug]-[12]:"Aw, snap!" error when rating widget is provided a large number as max value

2 participants