From 8e2922bccdc6aa9148886ce062c4b0078b2fda9e Mon Sep 17 00:00:00 2001 From: Cody Olsen Date: Fri, 13 Dec 2024 20:02:41 +0100 Subject: [PATCH] fix: remove unsafe ref mutation during render --- packages/sanity/src/router/RouteScope.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/sanity/src/router/RouteScope.tsx b/packages/sanity/src/router/RouteScope.tsx index aff8ed1d887..9f550220e13 100644 --- a/packages/sanity/src/router/RouteScope.tsx +++ b/packages/sanity/src/router/RouteScope.tsx @@ -1,5 +1,5 @@ /* eslint-disable camelcase */ -import {type ReactElement, type ReactNode, useCallback, useMemo, useRef} from 'react' +import {type ReactElement, type ReactNode, useCallback, useEffect, useMemo, useRef} from 'react' import {RouterContext} from 'sanity/_singletons' import {type NavigateOptions, type RouterContextValue, type RouterState} from './types' @@ -70,8 +70,9 @@ export function RouteScope(props: RouteScopeProps): ReactElement { parentRouter const parentStateRef = useRef(parentRouter.state) - - parentStateRef.current = parentRouter.state + useEffect(() => { + parentStateRef.current = parentRouter.state + }, [parentRouter.state]) const resolveNextParentState = useCallback( (_nextState: RouterState) => {