Skip to content

Commit 93bd0f2

Browse files
arbrandesclaude
andcommitted
fix: prioritize registration errors over inline validations in backendValidations
Registration errors from form submission (e.g., "password too similar to username") were being masked by stale inline validation results. The backendValidations memo checked state.validations first, which was set during on-blur field validation with no errors, causing it to never reach the registrationError branch. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0d709d1 commit 93bd0f2

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

src/register/components/RegisterContext.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,37 @@ describe('RegisterContext', () => {
322322
});
323323
});
324324

325+
it('should prioritize registrationError over validations for backendValidations', () => {
326+
const { result } = renderHook(() => useRegisterContext(), { wrapper });
327+
328+
// Simulate inline validation (on blur) setting validations
329+
act(() => {
330+
result.current.setValidationsSuccess({
331+
validationDecisions: {
332+
password: '',
333+
username: '',
334+
},
335+
});
336+
});
337+
338+
expect(result.current.backendValidations).toEqual({
339+
password: '',
340+
username: '',
341+
});
342+
343+
// Simulate form submission returning a registration error
344+
act(() => {
345+
result.current.setRegistrationError({
346+
errorCode: [{ userMessage: 'validation-error' }],
347+
password: [{ userMessage: 'The password is too similar to the username.' }],
348+
});
349+
});
350+
351+
expect(result.current.backendValidations).toEqual({
352+
password: 'The password is too similar to the username.',
353+
});
354+
});
355+
325356
it('should return null for backendValidations when neither validations nor registrationError exist', () => {
326357
const { result } = renderHook(() => useRegisterContext(), { wrapper });
327358
expect(result.current.backendValidations).toBe(null);

src/register/components/RegisterContext.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ export const RegisterProvider: FC<RegisterProviderProps> = ({ children }) => {
139139
}, []);
140140

141141
const backendValidations = useMemo(() => {
142-
if (state.validations) {
143-
return state.validations.validationDecisions;
144-
}
145-
146142
if (state.registrationError && Object.keys(state.registrationError).length > 0) {
147143
const fields = Object.keys(state.registrationError).filter(
148144
(fieldName) => !(['errorCode', 'usernameSuggestions'].includes(fieldName)),
@@ -155,6 +151,10 @@ export const RegisterProvider: FC<RegisterProviderProps> = ({ children }) => {
155151
return validationDecisions;
156152
}
157153

154+
if (state.validations) {
155+
return state.validations.validationDecisions;
156+
}
157+
158158
return null;
159159
}, [state.validations, state.registrationError]);
160160

0 commit comments

Comments
 (0)