Skip to content

fix(number): address number field precision edge cases#1474

Draft
Skaiir wants to merge 1 commit intomainfrom
1021-put-safeties-around-number-field
Draft

fix(number): address number field precision edge cases#1474
Skaiir wants to merge 1 commit intomainfrom
1021-put-safeties-around-number-field

Conversation

@Skaiir
Copy link
Copy Markdown
Contributor

@Skaiir Skaiir commented Feb 28, 2026

Closes #1021

Adds:

  • Warning when exceeding maximum numeric precision (:warning: we need to confirm this new warning pattern)
  • Disables the stepper arrows when they'd break due to numeric precision issues (like adding a 1e-6 step to 1e12)

@Skaiir Skaiir requested review from a team, barmac, Copilot and pablocabrera85 February 28, 2026 19:36
@bpmn-io-tasks bpmn-io-tasks Bot added the needs review Review pending label Feb 28, 2026
@Skaiir Skaiir requested review from vsgoulart and removed request for barmac, Copilot and pablocabrera85 February 28, 2026 19:36
@Skaiir Skaiir marked this pull request as draft February 28, 2026 21:47
@bpmn-io-tasks bpmn-io-tasks Bot added in progress Currently worked on and removed needs review Review pending labels Feb 28, 2026
@Skaiir Skaiir marked this pull request as ready for review February 28, 2026 21:47
Copilot AI review requested due to automatic review settings February 28, 2026 21:47
@bpmn-io-tasks bpmn-io-tasks Bot added needs review Review pending and removed in progress Currently worked on labels Feb 28, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Addresses numeric precision edge cases in the viewer’s Number field by detecting unsafe numeric inputs, warning users when typed values exceed JS Number precision, and preventing stepper interactions that would “stick” due to rounding.

Changes:

  • Added isNumberInputSafe() utility (with tests) to detect loss of precision through Number() conversion.
  • Updated Number field to show a non-error warning when typed values exceed supported precision.
  • Disabled stepper arrow UI when stepping would result in precision loss, plus added a reusable <Warning /> component + styling.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/form-js-viewer/test/spec/render/components/form-fields/util/numberFieldUtil.spec.js Adds unit tests for isNumberInputSafe() safe/unsafe cases.
packages/form-js-viewer/test/spec/render/components/form-fields/Number.spec.js Adds integration tests for arrow disabling and precision warning behavior (incl. serializeToString).
packages/form-js-viewer/src/render/components/util/numberFieldUtil.js Introduces isNumberInputSafe() utility used by Number field logic.
packages/form-js-viewer/src/render/components/form-fields/Number.js Implements arrow disabling + precision warnings and renders the new <Warning />.
packages/form-js-viewer/src/render/components/Warning.js New warning UI component to render non-error messages.
packages/form-js-viewer/assets/form-js-base.css Adds caution color token and warning styles; avoids error styling on disabled arrow container.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

decrementedValue = base.minus(offset).toFixed();
}

return !isNumberInputSafe(incrementedValue) && !isNumberInputSafe(decrementedValue);
Copy link

Copilot AI Feb 28, 2026

Choose a reason for hiding this comment

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

arrowsDisabled only becomes true when both the incremented and decremented values are unsafe (&&). This leaves cases where only one direction loses precision (e.g. base = 9007199254740992 with step = 1: increment is unsafe, decrement is safe) with both arrows enabled, so clicking increment can result in no underlying value change while the display updates to an unrepresentable string. Consider computing incrementDisabled/decrementDisabled separately (and disabling each button accordingly), or at least disabling arrows when either direction is unsafe.

Suggested change
return !isNumberInputSafe(incrementedValue) && !isNumberInputSafe(decrementedValue);
return !isNumberInputSafe(incrementedValue) || !isNumberInputSafe(decrementedValue);

Copilot uses AI. Check for mistakes.
@Skaiir Skaiir changed the base branch from develop to main February 28, 2026 22:41
--color-red-360-100-95: hsl(360, 100%, 95%);
--color-red-360-100-97: hsl(360, 100%, 97%);

--color-orange-33-100-40: hsl(33, 100%, 40%);
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.

@Skaiir We need to check the Carbonization of this on Tasklist

});
});

describe('high decimal digits without string serialization', function () {
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.

I know it's inconsistent on the codebase but I don't like that we're using class names for tests. We should use more accessible selectors which won't be coupled to implementation of the class names

@Skaiir Skaiir marked this pull request as draft March 12, 2026 16:08
@bpmn-io-tasks bpmn-io-tasks Bot added in progress Currently worked on and removed needs review Review pending labels Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in progress Currently worked on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Increment breaks when too many decimals are used in number fields

3 participants