fix: coerce AutoCompleteInput value to string to stop substring crash - #6959
Draft
superplanehq-integration[bot] wants to merge 2 commits into
Draft
Conversation
…769-0d6e71f8 Signed-off-by: SuperPlane Agent <superplaneagent@superplane.com>
AutoCompleteInput kept its editable state (inputValue) as a direct copy of the value prop, even though callers such as StringFieldRenderer and ExpressionFieldRenderer sometimes pass non-string config data (numbers, booleans, objects) despite the prop being typed as value?: string. When a non-string value reached the component, measureCursorPixelPosition called inputValue.substring(0, cursorPosition) on every value/cursor change and crashed with "TypeError: S.substring is not a function" (Sentry issue 7695184502), regressing PR #6014. Fix by coercing at the single source of truth: the initial useState, the previousInputValue ref, and the prop-sync effect all now normalize via a small toInputString() helper (value == null ? "" : String(value)), matching the pattern already used by TextFieldRenderer. This guarantees inputValue is always a string, so every other .substring/.trim/.slice call site in the component is protected, not just the one that crashed. Also added a defensive String() coercion at the measure-effect call site itself as a cheap extra guard. StringFieldRenderer and ExpressionFieldRenderer previously built their displayed value with a compile-time-only `as string` cast, which lets non-string config values pass straight through to AutoCompleteInput. Both now use the same null-safe String() coercion as TextFieldRenderer. Added regression tests covering number/boolean/object/null/undefined values for AutoCompleteInput and both field renderers, plus a happy-path check that normal string editing still calls onChange as expected. Signed-off-by: SuperPlane Agent <superplaneagent@superplane.com>
Contributor
Author
|
Maintainers: comment |
Contributor
Author
|
👋 Commands for maintainers:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Work Order.
Summary
AutoCompleteInputcrashed withTypeError: S.substring is not a function(Sentry issue 7695184502) when it received a non-stringvalue, for example a number or boolean stored in node configuration. The component storedvaluein state without checking its type, then called.substring()on it to measure the cursor position. This fix coerces the value to a string at the point where it enters the component state, and also fixes two field renderers that were passing unchecked values into the input. Tests were added to confirm the fix.UI
AutoCompleteInput.tsxtoInputString(value), that returns""fornull/undefinedandString(value)for anything else.valuefirst enters the component state: the initialuseState, thepreviousInputValueref, and the effect that re-syncs state when thevalueprop changes.measureCursorPixelPosition) as a second layer of protection, so the crash cannot happen even if a non-string value reaches that code by another path.inputValuealways a string, so all other string-only calls in the component (.trim(),.slice(),.length, etc.) are also protected, not only the one that crashed.StringFieldRenderer.tsx(value as string) ?? ""cast, which does not check the value at runtime, withvalue == null ? "" : String(value). This matches the pattern already used byTextFieldRenderer.ExpressionFieldRenderer.tsxvalueor, if that is missing,field.defaultValue.No changes were made to the API, workers, or database. This is a frontend-only fix.
Tests
Added new test files, colocated with the components:
AutoCompleteInput.spec.tsx: renders the component with number, boolean, object,null, andundefinedvalues and confirms it does not crash and shows the coerced text. Also confirms normal string input and typing still work as before.StringFieldRenderer.spec.tsxandExpressionFieldRenderer.spec.tsx: render each renderer with a non-string value, in both the expression (AutoCompleteInput) and plain (Input) modes, and confirm no crash and correct coerced text.Test plan
AutoCompleteInput.spec.tsx,StringFieldRenderer.spec.tsx,ExpressionFieldRenderer.spec.tsx)Created via SuperPlane.