Closed BrRenat closed 1 month ago
If the data is undefined or zero or empty string and etc, your promise will fail on timeout. To ensure that we don't wait for the API response, we should add a check for the loading property.
Sorry, the error has not occurred, but promise will never be resolved
@BrRenat
If the data is undefined or zero or empty string and etc, your promise will fail on timeout
Yeah, that's true. I have a couple of places where I try to "save bytes" and ignore correct type safety. For example, if you have a falsy key (0
or ""
) the library will go crazy and won't really work. I could make a type guard that would allow for such things, but ultimately I thought that doesn't make sense, because it's kind of artificial to have a cache key of 0
, isn't it?
Same goes for data
. I tried to come up with a non-artificial use case where a fetcher function (meaning, a function that fetches something from remote) will return raw falsy value, and I couldn't come up with one. Like, 9/10 cases for nanoquery is working with JSON API, and while mutations (PUT, POST, DELETE) can return empty body and that's fine (and mutations are ready for that), GET really shouldn't unless it's an error (which also can't be completely empty).
But maybe it's time to stop saving bytes here. Type guards won't take that much space.
Published in 0.3.4.
https://github.com/nanostores/query/blob/ac92fa1788c67e2350ae35ee1a03f322c72de8d5/lib/factory.ts#L299-L307
https://github.com/nanostores/query/commit/ac92fa1788c67e2350ae35ee1a03f322c72de8d5#r143713277