Skip to content

AK0061

Async validator timed out

What happened

An async validator (e.g., a server-side uniqueness check) did not resolve within the expected time limit. AkashJS treats the validation as failed after the timeout.

How to fix

Ensure your async validator resolves in a reasonable time. Check for network issues, slow endpoints, or missing error handling that could leave the promise hanging.

Example

ts
// Bad — validator may hang if the server is slow
const form = createForm({
  fields: {
    username: {
      validateAsync: async (value) => {
        const res = await fetch(`/api/check-username?u=${value}`);
        const data = await res.json();
        return data.available;
      },
    },
  },
});

// Good — add a timeout and error handling
const form = createForm({
  fields: {
    username: {
      validateAsync: async (value) => {
        try {
          const res = await fetch(`/api/check-username?u=${value}`, {
            signal: AbortSignal.timeout(3000),
          });
          const data = await res.json();
          return data.available;
        } catch {
          return false; // treat timeout/error as invalid
        }
      },
    },
  },
});

Released under the MIT License.