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

Fix refresh button breaks useGetList result with application cache #4829

Merged
merged 1 commit into from
May 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/ra-core/src/controller/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const useEditController = (props: EditProps): EditControllerProps => {
const refresh = useRefresh();
const version = useVersion();
const { data: record, loading, loaded } = useGetOne(resource, id, {
version, // used to force reload
action: CRUD_GET_ONE,
onFailure: () => {
notify('ra.notification.item_doesnt_exist', 'warning');
Expand Down
1 change: 0 additions & 1 deletion packages/ra-core/src/controller/useListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ const useListController = <RecordType = Record>(
{ ...query.filter, ...filter },
{
action: CRUD_GET_LIST,
version,
onFailure: error =>
notify(
typeof error === 'string'
Expand Down
1 change: 0 additions & 1 deletion packages/ra-core/src/controller/useShowController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const useShowController = (props: ShowProps): ShowControllerProps => {
const refresh = useRefresh();
const version = useVersion();
const { data: record, loading, loaded } = useGetOne(resource, id, {
version, // used to force reload
action: CRUD_GET_ONE,
onFailure: () => {
notify('ra.notification.item_doesnt_exist', 'warning');
Expand Down
2 changes: 1 addition & 1 deletion packages/ra-core/src/dataProvider/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import useDataProviderWithDeclarativeSideEffects from './useDataProviderWithDecl
const useQuery = (query: Query, options: QueryOptions = {}): UseQueryValue => {
const { type, resource, payload } = query;
const { withDeclarativeSideEffectsSupport, ...rest } = options;
const [state, setState] = useSafeSetState({
const [state, setState] = useSafeSetState<UseQueryValue>({
data: undefined,
error: null,
total: null,
Expand Down
4 changes: 3 additions & 1 deletion packages/ra-core/src/dataProvider/useQueryWithStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useSelector } from 'react-redux';
import isEqual from 'lodash/isEqual';

import useDataProvider from './useDataProvider';
import useVersion from '../controller/useVersion';
import getFetchType from './getFetchType';
import { useSafeSetState } from '../util/hooks';
import { ReduxState } from '../types';
Expand Down Expand Up @@ -120,7 +121,8 @@ const useQueryWithStore = (
loaded: boolean;
} => {
const { type, resource, payload } = query;
const requestSignature = JSON.stringify({ query, options });
const version = useVersion(); // used to allow force reload
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now even if the caller forgets to pass the version in the query options, the side effect will re-execute when a REFRESH_VIEW action is dispatched.

const requestSignature = JSON.stringify({ query, options, version });
const requestSignatureRef = useRef(requestSignature);
const data = useSelector(dataSelector);
const total = useSelector(totalSelector);
Expand Down