dillon1000/react

Commit

fix: restore selection should consider the window of the container (#30951)

## Summary


Fixes #30864 

Before this PR the active elemen was always taken from the global
`window`. This is incorrect if the renderer is in one window rendering
into a container element in another window. The changes in this PR adds
another code branch to use a `defaultView` of the container element if
it exists so that `restoreSelection` after a commit will actually
restore to the correct window.

## How did you test this change?

I patched these changes to the repro repo in the linked issue #39864
https://github.com/ling1726/react-child-window-focus-repro/blob/master/patches/react-dom%2B18.3.1.patch.

I followed the same repro steps in the linked issue and and could not
repro the reported problem. Attaching screen recordings below:

Before
![focus
repro](https://github.com/user-attachments/assets/81c4b4f9-08b5-4356-8251-49b909771f3f)

After

![after](https://github.com/user-attachments/assets/84883032-5558-4650-9b9a-bd4d5fd9cb13)
Browse files
Changed paths3 files
First-parent comparison
M packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js ModifiedM packages/react-dom-bindings/src/client/ReactInputSelection.js ModifiedM packages/react-dom/src/__tests__/ReactDOMFiber-test.js Modified
Patch

Files changed

Rendering syntax-highlighted changes…