React-admin: Hide loader in Reference Fields when the REST client call fails

Created on 11 Jul 2017  路  11Comments  路  Source: marmelab/react-admin

Sometimes when i return to resource list, the ReferenceArrayField is not updated and is stuck in loading state.

There is no request seen in network panel in Chrome.
And the only message is console is many of: finalize has been cancelled

I have not managed to reproduce it reliably, so i guess its some timeout thingie.

It would probably be nice if there was some timeout on the reference request?
And displaying some error icon with retry on click?

enhancement

Most helpful comment

I had a case where the server was responding with data, but I didn't include the Content Range header in my response. So the data was returned, but the progress spinner just stayed on. Very confusing to troubleshoot. I added it as a question+answer on stackoverflow in case it helps someone else.

https://stackoverflow.com/questions/52083078/referenceinput-field-shows-progress-bar-but-never-resolves/52083079#52083079

All 11 comments

If you can't give us a reliable way to reproduce it, there is no way we can fix it...

Feel free to reopen when you have a reliable failing test case.

well the only way i can reproduce it is to simulate network failure during fetching of the references

ie. i set slow network in chrome, and then set it to offline after fetching the list, but before the referenced fields are fetched

Just to rephrase: when your server doesn't return the response to a ReferenceArrayField request, it lets the field in loading state. It's probably true for every Reference field (not only ReferenceArrayField).

There is currently no way the ReferenceArrayField can detect a failure in the REST client call. All it does is update when the referenced data changes. But I can see why it's a problem.

I'm reopening and marking it as an enhancement request.

As a side note, this is probably VERY difficult. For instance, some REST clients make n requests to fetch references. If only one of those requests fails, how can the concerned Reference field know about it?

well the simplest fix would probably be to add one more prop named timeout (and set timeout based on it (with some aggregator to prevent too many settimeouts)) and if it elapses and the field is still in loading state, then mark it as failed

No, handling timeout is your rest client's business. For aor, a timeout isn't different from another REST failure. And aor components don't send REST requests directly anyway, so there is no way to determine if a REST failure is related to a given component.

@fzaninotto I think that the issue is "Too Many Attempts" (error code 429).
For example:
I have Country model and I have State model. When I edit the Country "United States" I use <ReferenceArrayField> to load the States (50). In the network console I can see many requests to load all chosen States (50 requests). This can be an issue if you are using "throttling" in your API. If I go back to the list or refresh the page I got "429" error code and the <ReferenceArrayField> is stuck in loading status.

This particular case depends on your restClient: the ReferenceArrayField actually make a CRUD_GET_MANY_ACCUMULATE action (accumulating all requested ids) and ends up with a final CRUD_GET_MANY.

Depending on your restClient, this final CRUD_GET_MANY may end up with multiple get requests but an optimized one should make only one request and retrieve all specified resources

@djhi Got it!

I had a case where the server was responding with data, but I didn't include the Content Range header in my response. So the data was returned, but the progress spinner just stayed on. Very confusing to troubleshoot. I added it as a question+answer on stackoverflow in case it helps someone else.

https://stackoverflow.com/questions/52083078/referenceinput-field-shows-progress-bar-but-never-resolves/52083079#52083079

fixed by #3550

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkyrychuk picture rkyrychuk  路  3Comments

Kmaschta picture Kmaschta  路  3Comments

9747749366 picture 9747749366  路  3Comments

mbj36 picture mbj36  路  3Comments

kdabir picture kdabir  路  3Comments