Hey folks, I have a question. Does anyone know how to use Astro Actions with an AbortController?
I am aware of the fact that you can use getActionPath() like this:
const formData = new FormData();
formData.append('image', entry.file);
const req = await fetch(getActionPath(actions.products.uploadImage),
{
method: 'POST',
signal: abortControllerRef.current?.signal,
body: formData,
});
const res = await req.json();
But there are 2 problems here.
- You lose type-safety. Perhaps this can be fixed with a type assertion, although I consider this a bit of a bad practice.
const res = await req.json() as Awaited<ReturnType<typeof actions.products.uploadImage>>;
- The above is actually incorrect, because the data returned is not in a regular format, and I probably need to use the devalue library to process the result.
My question is, is there an established or accepted pattern for this use case.
