It seems to be a bug with React 19. I have a similar problem, and I also tried multiple solutions such as setting the defaultValue for the <select></select>
tag, or conditionally checking the selected value for the <option></option>
tag to no avail.
You might as well try a more "manual" solution, which is to manipulate the DOM after the form state updates:
function createSpecialtyAction(prevState, formData) {
//...your code
const selectedValue = formData.get("schoolId");
const selectEl = document.querySelector("select#schoolId");
setTimeout(() => {
if (selectEl) selectEl.value = selectValue;
}, 100);
return {...yourState};
}
This solution guarantees that you retain your state after submitting the form, but comes with the drawback of giving a bit of UI flickering.