Skip to content

Commit fffdafe

Browse files
committed
fix(rp-connect): react to late-arriving KafkaInfo via rhf values
useForm captures defaultValues at mount; when the KafkaInfo query resolves after mount the RF field stays at its initial 3. Pass defaultValues through both `defaultValues` and `values` with `resetOptions: { keepDirtyValues: true }` so the form reactively picks up the clamped replicationFactor once brokersOnline is known, without clobbering fields the user has already edited.
1 parent 085867e commit fffdafe

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

frontend/src/components/pages/rp-connect/onboarding/add-topic-step.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,17 @@ export const AddTopicStep = forwardRef<BaseStepRef<AddTopicFormData>, AddTopicSt
124124
[defaultTopicName, defaultReplicationFactor]
125125
);
126126

127+
// Pass defaultValues AND values so react-hook-form reactively updates
128+
// replicationFactor when the KafkaInfo query resolves after mount. The
129+
// `values` prop is rhf's built-in mechanism for external reactive state;
130+
// `keepDirtyValues` prevents fields the user has already touched from
131+
// being overwritten when kafkaInfo lands late.
127132
const form = useForm<AddTopicFormData>({
128133
resolver: zodResolver(addTopicFormSchema),
129134
mode: 'onChange',
130135
defaultValues,
136+
values: defaultValues,
137+
resetOptions: { keepDirtyValues: true },
131138
});
132139

133140
const watchedTopicName = useWatch({

0 commit comments

Comments
 (0)