Skip to content

Commit 6f4b875

Browse files
committed
Renamed to fetching for clarity
And consistent with ancestorFetching. Also returned false if !show - didn't make sense that it returned true for fetching if it isn't showing
1 parent 5a09bd4 commit 6f4b875

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

NavigationReact/src/SceneRSCView.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ const SceneRSCView = ({active, name, refetch: serverRefetch, errorFallback, chil
3030
if (!rscCache.get(navigationEvent)) rscCache.set(navigationEvent, {});
3131
const cachedSceneViews = rscCache.get(navigationEvent);
3232
const renderedSceneView = useRef({sceneView: undefined, navigationEvent: undefined});
33-
const dataChanged = (() => {
33+
const fetching = (() => {
3434
const refetch = refetchRef.current;
35+
if (!show) return false;
3536
if (!getShow(oldState?.key) || !refetch || ignoreCache) return true;
3637
if (oldUrl && oldUrl.split('crumb=').length - 1 !== crumbs.length) return true;
3738
if (typeof refetch === 'function') return refetch(stateContext);
@@ -48,7 +49,7 @@ const SceneRSCView = ({active, name, refetch: serverRefetch, errorFallback, chil
4849
if (Object.keys(cachedSceneViews).length <= 1) rscCache.delete(navigationEvent);
4950
};
5051
}, [])
51-
if (!cachedSceneViews[sceneViewKey] && !cachedHistory && !firstScene && show && !ancestorFetching && dataChanged) {
52+
if (!cachedSceneViews[sceneViewKey] && !cachedHistory && !firstScene && !ancestorFetching && fetching) {
5253
cachedSceneViews[sceneViewKey] = deserialize(historyManager.getHref(url), {
5354
method: 'post',
5455
headers: {'Content-Type': 'application/json'},
@@ -59,7 +60,7 @@ const SceneRSCView = ({active, name, refetch: serverRefetch, errorFallback, chil
5960
if (!show) return null;
6061
if (cachedHistory) return historyCache[url][sceneViewKey];
6162
if (firstScene || ancestorFetching) return children;
62-
if (dataChanged) return cachedSceneViews[sceneViewKey];
63+
if (fetching) return cachedSceneViews[sceneViewKey];
6364
return renderedSceneView.current.sceneView;
6465
})();
6566
useEffect(() => {
@@ -91,10 +92,10 @@ const SceneRSCView = ({active, name, refetch: serverRefetch, errorFallback, chil
9192
window.addEventListener('popstate', cacheHistory);
9293
return () => window.removeEventListener('popstate', cacheHistory);
9394
});
94-
const fetching = ancestorFetching || dataChanged;
95-
const rscContextVal = useMemo(() => (
96-
{fetching, setRefetch: (refetch: any) => refetchRef.current = refetch !== undefined ? refetch : serverRefetch}
97-
), [fetching]);
95+
const rscContextVal = useMemo(() => ({
96+
fetching: ancestorFetching || fetching,
97+
setRefetch: (refetch: any) => refetchRef.current = refetch !== undefined ? refetch : serverRefetch
98+
}), [ancestorFetching || fetching]);
9899
return (
99100
<ErrorBoundary errorFallback={errorFallback}>
100101
<RSCContext.Provider value={rscContextVal}>

0 commit comments

Comments
 (0)