diff --git a/change/@fluentui-react-portal-cc923a38-5b66-41a7-95fb-306fefd5e3f4.json b/change/@fluentui-react-portal-cc923a38-5b66-41a7-95fb-306fefd5e3f4.json new file mode 100644 index 0000000000000..d33d08585afeb --- /dev/null +++ b/change/@fluentui-react-portal-cc923a38-5b66-41a7-95fb-306fefd5e3f4.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "clean up parent reference to avoid memory leaks", + "packageName": "@fluentui/react-portal", + "email": "arthurd@microsoft.com", + "dependentChangeType": "patch" +} diff --git a/packages/react-components/react-portal/src/components/Portal/usePortal.ts b/packages/react-components/react-portal/src/components/Portal/usePortal.ts index 66d748f5f6c23..dc69fccc93d03 100644 --- a/packages/react-components/react-portal/src/components/Portal/usePortal.ts +++ b/packages/react-components/react-portal/src/components/Portal/usePortal.ts @@ -26,6 +26,9 @@ export const usePortal_unstable = (props: PortalProps): PortalState => { if (state.virtualParentRootRef.current && state.mountNode) { setVirtualParent(state.mountNode, state.virtualParentRootRef.current); } + return () => { + if (state.mountNode) {setVirtualParent(state.mountNode, undefined);} + }; }, [state.virtualParentRootRef, state.mountNode]); return state;