Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass through refresh property to data provider? #3617

Closed
yelworc opened this issue Aug 28, 2019 · 4 comments
Closed

Pass through refresh property to data provider? #3617

yelworc opened this issue Aug 28, 2019 · 4 comments

Comments

@yelworc
Copy link
Contributor

yelworc commented Aug 28, 2019

Is your feature request related to a problem? Please describe.
When working with API resources in react-admin (e.g. displaying objects in a List view), changes made through another client are not visible. Clicking the "refresh" icon in the title bar does not help because of HTTP caching. The only way to see recent changes (beyond waiting for the cached responses to expire) is clearing the browser cache.

Describe the solution you'd like
I noticed there is already a refresh property in some CRUD actions (e.g. crudGetOne), so I was wondering if it would make sense to add that to all those actions, and pass it through to the data provider (e.g. in params). The provider could then set HTTP headers to bypass the cache (Cache-Control: must-revalidate, I suppose).

Describe alternatives you've considered
Haven't really thought about alternative solutions yet, but totally open to suggestions.

If the above idea sounds reasonable, and would be a suitable first contribution (not touching too many parts of the codebase, etc), I'd be up for working on a PR.

@fzaninotto
Copy link
Member

The refresh property in actions tells react-admin to refresh the view, not to pass a refresh to the dataProvider. It's different semantics, and besides, it's been removed in 3.0.

I don't see how react-admin could pass that information to the dataProvider. React-admin can't guess your caching policy. In my opinion, it's your job to write a dataProvider that sends a must-revalidate after a PUT, a POST or a DELETE on a resource.

So I'm closing it as it can be solved in userland (in your dataProvider).

@yelworc
Copy link
Contributor Author

yelworc commented Aug 28, 2019

Hmm… your approach (revalidate after previous non-idempotent requests) only applies to the scenario where something was changed in "this" instance of react-admin. The more general case, where data has been modified through any other means, can't be solved that way.

You're totally right that react-admin can't guess caching policies, but when the user explicitly expresses they want to see up-to-date data (by clicking the refresh icon), I think it would make sense to pass this intent to the data provider somehow.

I agree that the refresh prop in CRUD actions should not be used for this purpose, as it has a different meaning.

@fzaninotto
Copy link
Member

fzaninotto commented Aug 28, 2019

In react-admin, the path between the click on Refresh and the actual queries in the data provider takes many, many steps, and passing parameters through these steps isn't possible. So I suggest you solve this in userland, by implementing your own RefreshButton that stores a boolean in sessionStorage to force refresh, and the dataProvider can read this boolean before making requests.

@yelworc
Copy link
Contributor Author

yelworc commented Aug 28, 2019

Alright – thanks for taking the time to explain!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants