-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom save doesn't redirect onSuccess due to warnWhenUnsavedChanges #7608
Comments
Reproduced, thanks! |
In the case you return a promise, you should handle the side effects when the promise resolves: update(
'posts',
{
id: values.id,
data: values,
},
{
returnPromise: true,
mutationMode: 'pessimistic',
onError: error => {
notify((error as Error).message, { type: 'error' });
},
}
).then(() => {
notify('it worked');
redirect('show', 'posts', values.id);
}); I'm marking this as a documentation issue |
How this works together with server side validation? If I await update and return errors it does not redirect, if I don't await update it does not show server side errors |
Is there any way to make this work together with server side validation? I would also be very much interested in that. 😄 |
i'm seeing this problem with a create form where i want to redirect to the edit after a custom save and it only works without warnWhenUnsavedChanges. i am doing
|
Is this issue still open? |
it should be, i am still having the same issues with warnWhenUnsavedChanges and custom saves |
I was experiencing the same issue. I think the redirect navigation is attempted at a point where the form is still blocked for navigating, since it was not yet registered that the form is not dirty anymore. So using patch package I made the following modifications in @@ -151,7 +152,7 @@ export var useEditController = function (props) {
messageArgs: { smart_count: 1 },
undoable: mutationMode === 'undoable',
});
- redirect(redirectTo, resource, data.id, data);
+ setTimeout(() => redirect(redirectTo, resource, data.id, data), 50);
return [2 /*return*/];
});
}); }, |
I have the same with
|
EDIT: per #7608 (comment) it seems like I still haven't figured out 100% of the issue. Especially the following assumption I made, is wrong:
So please keep a critical mind when reading my answer below 😇 Thought I'd add some clarifications about this issue. You will run into this issue if both conditions are true:
If you provide neither custom If you provide a custom Regarding the questions about server-side validation, I'm not sure I understand the issue there, but to my understanding you can handle the errors in a catch block: const update = useUpdate(resource, data, {mutationMode: 'pessimistic', returnPromise: true});
try {
const result = await update(resource, data)
console.log(result)
} catch (error) {
// handle server side errors here
console.error(error)
} finally {
console.log('done')
} Hope this helps! |
This is counter-intuitive. Are you sure about this one? |
@fzaninotto I have double-checked, and indeed it appears I was wrong about this!! |
Now that #8882 has been merged I'm wondering if we can consider this issue fixed as well. Can s.o. give it a try to check if their issue is resolved or not? Thanks! |
What you were expecting:
When I submit the form the data is saved, the user is notified, and then the user is redirected to the specified page
What happened instead:
The notification is fired however the user is not redirected
Steps to reproduce:
Then remove warnWhenUnsavedChanges from the tabbed form.
Repeat the steps and you will be redirected.
Related code:
https://codesandbox.io/s/nervous-zeh-bxj6ym?file=/src/posts/PostEdit.tsx:2071-2093
Other information:
It appears that warnWhenUnsavedChanges is interfering with the redirection of the page
Environment
The text was updated successfully, but these errors were encountered: