-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Update refresh strategy to avoid empty page while refreshing #6054
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import { useCallback } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { refreshView } from '../actions/uiActions'; | ||
import { refreshView, softRefreshView } from '../actions/uiActions'; | ||
|
||
/** | ||
* Hook for Refresh Side Effect | ||
* | ||
* Returns a callback that triggers a page refresh. The callback causes a | ||
* version increase, which forces a re-execution all queries based on the | ||
* useDataProvider() hook, and a rerender of all components using the version | ||
* as key. | ||
* | ||
* @param hard If true, the callback empties the cache, too | ||
* | ||
* @example | ||
* | ||
* const refresh = useRefresh(); | ||
* // soft refresh | ||
* refresh(); | ||
* // hard refresh | ||
* refresh(true) | ||
*/ | ||
const useRefresh = () => { | ||
const dispatch = useDispatch(); | ||
return useCallback( | ||
(doRefresh = true) => doRefresh && dispatch(refreshView()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this doRefresh parameter was undocumented and unused. Also, it's useless - one can replace it easily: -refresh(doRefresh);
+doRefresh && refresh() |
||
(hard?: boolean) => { | ||
dispatch(hard ? refreshView() : softRefreshView()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wondered if there should be two different actions or one action with a variable payload. I'm open to discussion on this point There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a single action is enough, with a type option which can be either |
||
}, | ||
[dispatch] | ||
); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the key difference: a soft_refresh doesn't empty the cached requests, only invalidates them