Skip to content

[all components] Use WeakRef for previously focused elements - #3916

Merged
atomiks merged 2 commits into
mui:masterfrom
atomiks:focus-manager-weakref
Feb 11, 2026
Merged

atomiks merged 2 commits into
mui:masterfrom
atomiks:focus-manager-weakref

Conversation

@atomiks

@atomiks atomiks commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

This prevents detached nodes from being held in the array before they may be cleared. Currently there's a limit of 20 nodes and they get cleared whenever a popup mounts/unmounts but this is not fully robust.

@atomiks atomiks added type: bug It doesn't behave as expected. scope: all components Widespread work has an impact on almost all components. labels Feb 1, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 1, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@3916
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@3916
    

commit: 38a8d06

@mui-bot

mui-bot commented Feb 1, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+31B(+0.01%) 🔺+16B(+0.01%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Feb 1, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 38a8d06
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/698c35d4d7387d000814e33b
😎 Deploy Preview https://deploy-preview-3916--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the focus-manager-weakref branch from 6b9a9fb to e2eca76 Compare February 1, 2026 19:51
@atomiks
atomiks force-pushed the focus-manager-weakref branch from e2eca76 to a721827 Compare February 1, 2026 19:52
@atomiks
atomiks marked this pull request as ready for review February 1, 2026 19:56
@greptile-apps

greptile-apps Bot commented Feb 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR updates FloatingFocusManager's tracking of previously focused elements to store WeakRef<Element> entries instead of strong Element references, and adjusts cleanup/retrieval to deref() the element and drop entries whose targets were GC'd or disconnected. This reduces the chance of retaining detached DOM nodes across popup lifecycles while preserving existing return-focus and focus-out behavior.

Confidence Score: 4/5

  • This PR is likely safe to merge and should reduce detached-node retention risk.
  • The change is localized and preserves call sites/semantics by deref'ing WeakRefs before use; the main residual risk is runtime support for WeakRef in any supported environments/build targets.
  • packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx

Important Files Changed

Filename Overview
packages/react/src/floating-ui-react/components/FloatingFocusManager.tsx Replaces strong refs with WeakRef for previouslyFocusedElements and updates add/get/cleanup logic to avoid retaining detached nodes.

@mnajdova mnajdova left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@atomiks
atomiks merged commit 04f5187 into mui:master Feb 11, 2026
7 checks passed
@atomiks
atomiks deleted the focus-manager-weakref branch February 11, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants