korbit-ai[bot] commented on code in PR #35215:
URL: https://github.com/apache/superset/pull/35215#discussion_r2362870061
##########
superset-frontend/src/dashboard/components/PropertiesModal/sections/BasicInfoSection.tsx:
##########
@@ -31,54 +31,56 @@ const BasicInfoSection = ({
form,
isLoading,
validationStatus,
-}: BasicInfoSectionProps) => (
- <>
- <ModalFormField
- label={t('Name')}
- required
- testId="dashboard-name-field"
- error={
- validationStatus.basic?.hasErrors &&
- (!form.getFieldValue('title') ||
- form.getFieldValue('title').trim().length === 0)
- ? t('Dashboard name is required')
- : undefined
- }
- >
- <FormItem
- name="title"
- noStyle
- rules={[
- {
- required: true,
- message: t('Dashboard name is required'),
- whitespace: true,
- },
- ]}
+}: BasicInfoSectionProps) => {
+ const titleValue = form.getFieldValue('title');
+ const hasError =
+ !isLoading &&
+ validationStatus.basic?.hasErrors &&
+ (!titleValue || titleValue.trim().length === 0);
Review Comment:
### Stale form value in error calculation <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
The titleValue is retrieved once during component render and stored in a
variable, but form field values can change during user interaction without
triggering a re-render of this computed value.
###### Why this matters
This creates a stale closure where hasError will continue to use the initial
titleValue even after the user types in the input field, causing validation
errors to persist incorrectly or not appear when they should.
###### Suggested change ∙ *Feature Preview*
Move the form value retrieval inside the error calculation or use a function
to get the current value:
```typescript
const hasError =
!isLoading &&
validationStatus.basic?.hasErrors &&
(() => {
const currentTitleValue = form.getFieldValue('title');
return !currentTitleValue || currentTitleValue.trim().length === 0;
})();
```
Or alternatively, remove the variable and inline the form.getFieldValue call
in the hasError calculation.
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/81acda0d-7a8c-451f-ad90-7ffb9133a3a1/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/81acda0d-7a8c-451f-ad90-7ffb9133a3a1?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/81acda0d-7a8c-451f-ad90-7ffb9133a3a1?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/81acda0d-7a8c-451f-ad90-7ffb9133a3a1?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/81acda0d-7a8c-451f-ad90-7ffb9133a3a1)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:5843d837-0a7f-4aa3-82fd-a4db86c5c61e -->
[](5843d837-0a7f-4aa3-82fd-a4db86c5c61e)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]