Skip to content

Commit 09d8283

Browse files
authored
[ez] Rewrite optional chaining and nullish coalescing syntax (#30982)
Rewrite `containerInfo?.ownerDocument?.defaultView ?? window` to instead use a ternary. This changes the compilation output (see [bundle changes from #30951](d65fb06)). ```js // compilation of containerInfo?.ownerDocument?.defaultView ?? window var $jscomp$optchain$tmpm1756096108$1, $jscomp$nullish$tmp0; containerInfo = null != ($jscomp$nullish$tmp0 = null == containerInfo ? void 0 : null == ($jscomp$optchain$tmpm1756096108$1 = containerInfo.ownerDocument) ? void 0 : $jscomp$optchain$tmpm1756096108$1.defaultView) ? $jscomp$nullish$tmp0 : window; // compilation of ternary expression containerInfo = null != containerInfo && null != containerInfo.ownerDocument && null != containerInfo.ownerDocument.defaultView ? containerInfo.ownerDocument.defaultView : window; ``` This also reduces the number of no-op bundle syncs for Meta. Note that Closure compiler's `jscomp$optchain$tmp<HASH>` identifiers change when we rebuild (likely due to version number changes). See [workflow](https://github.com/facebook/react/actions/runs/10891164281/job/30221518374) for a PR that was synced despite making no changes to the runtime.
1 parent f2c57a3 commit 09d8283

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

packages/react-dom-bindings/src/client/ReactInputSelection.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ function isSameOriginFrame(iframe) {
5757
}
5858

5959
function getActiveElementDeep(containerInfo) {
60-
let win = containerInfo?.ownerDocument?.defaultView ?? window;
60+
let win =
61+
containerInfo != null &&
62+
containerInfo.ownerDocument != null &&
63+
containerInfo.ownerDocument.defaultView != null
64+
? containerInfo.ownerDocument.defaultView
65+
: window;
6166
let element = getActiveElement(win.document);
6267
while (element instanceof win.HTMLIFrameElement) {
6368
if (isSameOriginFrame(element)) {

0 commit comments

Comments
 (0)