I recreated your server action system without the validation and email sending. The server action correctly returns the object with success property to the formData variable and renders the component accordingly. Are you sure that any other part of the code before the return doesn't raise any unexpected errors which could result in invalid error handling? This is the server action code on which i tested the functionality
export const actions = {
contactus: async ({ request }) => {
const formData = Object.fromEntries(await request.formData());
try {
if (
!formData.fullName ||
!formData.email ||
!formData.phone ||
!formData.address
) {
throw new Error('All field must be filled out');
}
return {
success: true,
};
} catch (err) {
return {
formData: JSON.stringify(formData),
error: err.message,
};
}
},
};