sergiodxa / remix-utils

A set of utility functions and types to use with Remix.run
https://sergiodxa.github.io/remix-utils/
MIT License
2.06k stars 116 forks source link

`getFetcherType` doesn't return `done` after submit #323

Open Xelson opened 5 months ago

Xelson commented 5 months ago

Describe the bug

If a fetcher submitting to an action handler that returns null then getFetcherType returns idle after submission instead of done. This happens because the initial fetcher.data value is undefined, but in the code if (fetcher.state === "idle" && fetcher.data != null) return "done", fetcher.data is being checked for null

Your Example Website or App

https://stackblitz.com/edit/remix-run-remix-hpas2u?file=app%2Froutes%2F_index.tsx

Steps to Reproduce the Bug or Issue

  1. Go to stackblitz page with reproduce example;
  2. Press every button on the page. The alert about submission will appear only after pressing the second one.

Expected behavior

If fetcher is triggering action which returning null value, getFetcherType should be done, not idle

Screenshots or Videos

No response

Platform

Additional context

No response