From 38a5f2dbbf57680e5519f5dbfa2098fd31efcae4 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Tue, 20 Apr 2021 20:48:40 -0700 Subject: [PATCH] Ensure allocations are persisted across page navigation correctly; closes #2729 --- .../components/server/network/NetworkContainer.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/resources/scripts/components/server/network/NetworkContainer.tsx b/resources/scripts/components/server/network/NetworkContainer.tsx index fdc66aa6d..0bb6bd42a 100644 --- a/resources/scripts/components/server/network/NetworkContainer.tsx +++ b/resources/scripts/components/server/network/NetworkContainer.tsx @@ -11,6 +11,7 @@ import Can from '@/components/elements/Can'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import getServerAllocations from '@/api/swr/getServerAllocations'; import isEqual from 'react-fast-compare'; +import { useDeepCompareEffect } from '@/plugins/useDeepCompareEffect'; const NetworkContainer = () => { const [ loading, setLoading ] = useState(false); @@ -23,7 +24,7 @@ const NetworkContainer = () => { const { data, error, mutate } = getServerAllocations(); useEffect(() => { - mutate(allocations, false); + mutate(allocations); }, []); useEffect(() => { @@ -32,6 +33,12 @@ const NetworkContainer = () => { } }, [ error ]); + useDeepCompareEffect(() => { + if (!data) return; + + setServerFromState(state => ({ ...state, allocations: data })); + }, [ data ]); + const onCreateAllocation = () => { clearFlashes('server:network');