Skip to content
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

feat: console.debug when auto saves are skipped. #105

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/useFormState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ export function useFormState<T, I>(opts: UseFormStateOpts<T, I>): ObjectState<T>
}

// Don't use canSave() because we don't want to set touched for all the fields
if (autoSaveRef.current && form.dirty && form.valid && !isAutoSaving) {
if (autoSaveRef.current && form.dirty && !isAutoSaving) {
// It's very frustrating to not know why the form is savings, to go ahead and log these
if (!form.valid) {
console.debug("Skipping auto-save b/c form is invalid: ", form.errors);
return;
}
isAutoSaving = "queued";
let maybeError: undefined | string;
// We use setTimeout as a cheap way to wait until the end of the current event listener
Expand Down
9 changes: 7 additions & 2 deletions src/useFormStates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,13 @@ export function useFormStates<T, I = T>(opts: UseFormStatesOpts<T, I>): UseFormS
let form = existing?.[0];

async function maybeAutoSave(form: ObjectState<T>) {
// Don't use canSave() because we don't want to set touched for all the fields
if (autoSaveRef.current && form.dirty && form.valid) {
// Don't use form.canSave() because we don't want to set touched for all the fields
if (autoSaveRef.current && form.dirty) {
// It's very frustrating to not know why the form is savings, to go ahead and log these
if (!form.valid) {
console.debug("Skipping auto-save b/c form is invalid: ", form.errors);
return;
}
const { current: pending } = pendingAutoSaves;
if (isAutoSaving) {
pending.add(form);
Expand Down
Loading