Skip to content

Fix #1638: render form validation errors with getError instead of getHelper#1639

Open
zerberu5 wants to merge 1 commit into
apache:mainfrom
zerberu5:fix/form-error-rendering
Open

Fix #1638: render form validation errors with getError instead of getHelper#1639
zerberu5 wants to merge 1 commit into
apache:mainfrom
zerberu5:fix/form-error-rendering

Conversation

@zerberu5

Copy link
Copy Markdown

Fixes #1638

Problem

useFormUtil has two renderers for the text below a form field:

  • getHelper(text?: string) — renders its argument directly
  • getError(error: FieldError | undefined) — renders error.message

Three helpers passed a react-hook-form FieldError object to getHelper, so the object was rendered as a React child and React threw "Objects are not valid as a React child (found: object with keys {ref, type, message})", taking down the surrounding panel via the ErrorBoundary.

Because getHelper is declared to take a string, the as any cast at the call sites hid the type mismatch.

Change

Use getError at the three affected call sites in useFormUtil.tsx:

line helper reachable from UI before this change
235 getTextFieldPrefix no current caller
265 getTextFieldSuffix yesCreateProjectModal.tsx:156
290 getFormSelect no current caller

The getTextFieldSuffix case is the user-visible one. CreateProjectModal validates with mode: "all" and requires a name longer than 3 characters, so the first character typed into the Name field always produced an error object and crashed the dialog — making the name impossible to type. Pasting a valid name worked, since onChange then fired once with a value that passed validation.

The other two are latent and would fail the same way as soon as a caller adds validation.

Verification

Reproduced on main by typing a single character into the Name field of the create dialog, then confirmed with this change applied that the same keystroke renders the expected File name should be longer that 3 characters message and the dialog behaves normally.

Note, not addressed here

getTextFieldSuffix also has its invalid-state styling commented out (// validated={...}, line 254), so the field is not visually marked as invalid even now that the message renders. Left alone to keep this change minimal.

Render validation errors with getError instead of getHelper.

getTextFieldPrefix, getTextFieldSuffix and getFormSelect passed a
react-hook-form FieldError object to getHelper, which renders its
argument directly as a React child. Since getHelper is declared to
take a string, the `as any` cast at the call sites hid the mismatch,
and any failing validation crashed the surrounding panel with
"Objects are not valid as a React child".

getError already exists for this and renders error.message.

Reachable via CreateProjectModal, which validates on every keystroke
and requires a name longer than 3 characters, so the dialog crashed
on the first character typed.
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.

UI crash (React #31) when typing an invalid name in the Create Project/File/Kamelet dialog

1 participant