diff --git a/change/@fluentui-react-motion-preview-9ee2031a-5268-4dd5-8f34-060e985b7d22.json b/change/@fluentui-react-motion-preview-9ee2031a-5268-4dd5-8f34-060e985b7d22.json new file mode 100644 index 00000000000000..ea0aa729caa843 --- /dev/null +++ b/change/@fluentui-react-motion-preview-9ee2031a-5268-4dd5-8f34-060e985b7d22.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix: sync internal value of canRender with presence", + "packageName": "@fluentui/react-motion-preview", + "email": "marcosvmmoura@gmail.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-motion-preview/src/hooks/useMotion.test.ts b/packages/react-components/react-motion-preview/src/hooks/useMotion.test.ts index 2a8f39a7e45058..946bf69a713e54 100644 --- a/packages/react-components/react-motion-preview/src/hooks/useMotion.test.ts +++ b/packages/react-components/react-motion-preview/src/hooks/useMotion.test.ts @@ -64,6 +64,15 @@ describe('useMotion', () => { }); describe('when motion is received', () => { + it('should sync presence value with canRender', () => { + const { result, rerender } = renderHookWithRef(false); + + expect(result.current.canRender).toBe(false); + rerender(true); + + expect(result.current.canRender).toBe(true); + }); + it('should return default values when presence is false', () => { const defaultState = getDefaultMotionState(); const { result } = renderHookWithRef(getDefaultMotionState()); diff --git a/packages/react-components/react-motion-preview/src/hooks/useMotion.ts b/packages/react-components/react-motion-preview/src/hooks/useMotion.ts index 76e903866f6b4f..0a5db898a9b3bc 100644 --- a/packages/react-components/react-motion-preview/src/hooks/useMotion.ts +++ b/packages/react-components/react-motion-preview/src/hooks/useMotion.ts @@ -177,11 +177,11 @@ function useMotionPresence( ref, type, active, - canRender: type !== 'unmounted', + canRender: presence || type !== 'unmounted', }), // No need to add ref to the deps array as it is stable // eslint-disable-next-line react-hooks/exhaustive-deps - [active, type], + [active, type, presence], ); }