Skip to content

Commit

Permalink
fix: restore selection should consider the window of the container (#…
Browse files Browse the repository at this point in the history
…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)

DiffTrain build for [d9c4920](d9c4920)
  • Loading branch information
josephsavona committed Sep 13, 2024
1 parent 9d3ed27 commit d65fb06
Show file tree
Hide file tree
Showing 34 changed files with 4,044 additions and 3,903 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3d4d3a46b014ab0f6edc443c19fcdba09105f20
d9c4920e8b3fff3d3da24d14adf7ac884aee55b2
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION_TRANSFORMS
Original file line number Diff line number Diff line change
@@ -1 +1 @@
d3d4d3a46b014ab0f6edc443c19fcdba09105f20
d9c4920e8b3fff3d3da24d14adf7ac884aee55b2
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2001,7 +2001,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-classic-d3d4d3a4-20240913";
exports.version = "19.0.0-www-classic-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ __DEV__ &&
exports.useTransition = function () {
return resolveDispatcher().useTransition();
};
exports.version = "19.0.0-www-modern-d3d4d3a4-20240913";
exports.version = "19.0.0-www-modern-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-d3d4d3a4-20240913";
exports.version = "19.0.0-www-classic-d9c4920e-20240913";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,4 +665,4 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-d3d4d3a4-20240913";
exports.version = "19.0.0-www-modern-d9c4920e-20240913";
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-classic-d3d4d3a4-20240913";
exports.version = "19.0.0-www-classic-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
2 changes: 1 addition & 1 deletion compiled/facebook-www/React-profiling.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ exports.useSyncExternalStore = function (
exports.useTransition = function () {
return ReactSharedInternals.H.useTransition();
};
exports.version = "19.0.0-www-modern-d3d4d3a4-20240913";
exports.version = "19.0.0-www-modern-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -17112,11 +17112,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-classic-d3d4d3a4-20240913",
version: "19.0.0-www-classic-d9c4920e-20240913",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-classic-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-www-classic-d9c4920e-20240913"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -17150,7 +17150,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-d3d4d3a4-20240913";
exports.version = "19.0.0-www-classic-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -16558,11 +16558,11 @@ __DEV__ &&
(function () {
var internals = {
bundleType: 1,
version: "19.0.0-www-modern-d3d4d3a4-20240913",
version: "19.0.0-www-modern-d9c4920e-20240913",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: getInstanceFromNode,
reconcilerVersion: "19.0.0-www-modern-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-www-modern-d9c4920e-20240913"
};
internals.overrideHookState = overrideHookState;
internals.overrideHookStateDeletePath = overrideHookStateDeletePath;
Expand Down Expand Up @@ -16596,7 +16596,7 @@ __DEV__ &&
exports.Shape = Shape;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-d3d4d3a4-20240913";
exports.version = "19.0.0-www-modern-d9c4920e-20240913";
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ &&
"function" ===
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop &&
Expand Down
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -10883,13 +10883,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1424 = {
bundleType: 0,
version: "19.0.0-www-classic-d3d4d3a4-20240913",
version: "19.0.0-www-classic-d9c4920e-20240913",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-classic-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-www-classic-d9c4920e-20240913"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1425 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10915,4 +10915,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-classic-d3d4d3a4-20240913";
exports.version = "19.0.0-www-classic-d9c4920e-20240913";
6 changes: 3 additions & 3 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -10397,13 +10397,13 @@ var slice = Array.prototype.slice,
})(React.Component);
var internals$jscomp$inline_1416 = {
bundleType: 0,
version: "19.0.0-www-modern-d3d4d3a4-20240913",
version: "19.0.0-www-modern-d9c4920e-20240913",
rendererPackageName: "react-art",
currentDispatcherRef: ReactSharedInternals,
findFiberByHostInstance: function () {
return null;
},
reconcilerVersion: "19.0.0-www-modern-d3d4d3a4-20240913"
reconcilerVersion: "19.0.0-www-modern-d9c4920e-20240913"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1417 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand All @@ -10429,4 +10429,4 @@ exports.RadialGradient = RadialGradient;
exports.Shape = TYPES.SHAPE;
exports.Surface = Surface;
exports.Text = Text;
exports.version = "19.0.0-www-modern-d3d4d3a4-20240913";
exports.version = "19.0.0-www-modern-d9c4920e-20240913";
Loading

0 comments on commit d65fb06

Please sign in to comment.