Force GET_ONE request when navigating to Show page
Asked Answered
H

1

16

As I believe is common in many APIs, ours returns a subset of fields for a record when it is part of a List request, and more details when it is a single-record request to its Show endpoint.

It seems that react-admin attempts to avoid doing a second request when loading a Show page (possibly re-using the record data from List?), which results in missing data. Refreshing the page fixes this, but I'm wondering if there is a setting that will force a GET_ONE request on every Show page load.

Hansen answered 19/7, 2018 at 19:15 Comment(0)
G
9

There are no setting for that. However, this should be achievable with a custom saga which would listen to LOCATION_CHANGE action (from react-redux-router) and dispatch a refreshView action (from react-admin) when the new location pathname ends with /show.

Edit: however this is very strange. We only use the data we already got from the list for optimistic display but we still request with a GET_ONE when navigating to a show page from the list. Do you have a codesandbox showing your issue?

Gumwood answered 25/7, 2018 at 15:6 Comment(2)
The problem seemed to be that the page was rendering before that GET_ONE request completed, presumably with the list data, and we weren't correctly handling the case where those fields were unavailable. We added conditionals to our code to only render if available and all works as expected. Is this behavior documented anywhere?Hansen
Yes, that's optimistic UI. We first render with the data we have so that the app looks fast. We should probably document this betterGumwood

© 2022 - 2024 — McMap. All rights reserved.