You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Show feedback for oversized flag values
#8920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
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
The reason will be displayed to describe this comment to others. Learn more.
Trivial · Maintainability & Code Quality · Heavy lift
Test value-length validation through the save paths.
Add integration tests for oversized control, variant and segment values during flag creation, direct saves and change requests. Assert that saving is blocked and the editor shows an alert. Also assert that saving succeeds when the only oversized segment override is marked for removal.
These tests would protect the save guard and removal exception, which the utility tests do not exercise.
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
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
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
nl -ba frontend/common/utils/utils.tsx | sed -n '575,645p;825,865p'
nl -ba frontend/common/utils/featureStateToValue.ts
Repository: Flagsmith/flagsmith
Length of output: 5457
Memoise the length check for unchanged editors.
When many variants have large values, editing one variant recounts every unchanged value and allocates an array for each. This can cause typing lag. Memoise the check so unchanged editors reuse their results.
Suggested fix
--- "a/frontend/web/components/ValueEditor/ValueEditor.tsx"+++ "b/frontend/web/components/ValueEditor/ValueEditor.tsx"@@ -63,13 +63,17 @@
const language = languageProp ?? picked ?? detected ?? 'txt'
const labelId = useId()
const text = value === undefined || value === null ? '' : `${value}`
- const lengthError = validateLength- ? getFeatureValueLengthError(- text,- typeof label === 'string' ? label : 'Value',- MAX_FEATURE_VALUE_LENGTH,- )- : undefined+ const lengthError = useMemo(+ () =>+ validateLength+ ? getFeatureValueLengthError(+ text,+ typeof label === 'string' ? label : 'Value',+ MAX_FEATURE_VALUE_LENGTH,+ )+ : undefined,+ [text, label, validateLength],+ )
// Detection waits for a value rather than running on mount: values load
// after mount, and a mount-only check left JSON rendering as plaintext.
Committable suggestion
IMPORTANT
Review the replacement and indentation, then test before committing.
Suggested change
constlengthError=validateLength
? getFeatureValueLengthError(
text,
typeoflabel==='string' ? label : 'Value',
MAX_FEATURE_VALUE_LENGTH,
)
: undefined
constlengthError=useMemo(
()=>
validateLength
? getFeatureValueLengthError(
text,
typeoflabel==='string' ? label : 'Value',
MAX_FEATURE_VALUE_LENGTH,
)
: undefined,
[text,label,validateLength],
)
// Detection waits for a value rather than running on mount: values load
// after mount, and a mount-only check left JSON rendering as plaintext.
Forward the invalid state to the editable textbox.
When a value exceeds the limit, Highlight drops aria-invalid, so the textbox does not expose its invalid state to assistive technology. Forward the prop to the <code> element and include it in shouldComponentUpdate so the state updates during editing.
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
A flag value with 20,000 characters followed by a space is rejected, although direct save trims it. Change-request payloads also use the trimmed value. Use that value for the modal’s change comparison as well.
If several values exceed the limit, one save creates a toast for each value. The stack can cover the editor for five seconds. Show one summary toast while preserving the individual error details.
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test value-length validation through the save paths.
Add integration tests for oversized control, variant and segment values during flag creation, direct saves and change requests. Assert that saving is blocked and the editor shows an alert. Also assert that saving succeeds when the only oversized segment override is marked for removal.
These tests would protect the save guard and removal exception, which the utility tests do not exercise.