Skip to content

Commit 87d09a8

Browse files
committed
Fix traversal order, remove focus mocks
1 parent 67efec9 commit 87d09a8

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,16 +1659,17 @@ function recursivelyGetFragmentInstanceChildren(
16591659
return;
16601660
}
16611661

1662+
if (child.tag === HostComponent) {
1663+
childElements.add(child.stateNode);
1664+
}
1665+
16621666
if (child.sibling !== null) {
16631667
recursivelyGetFragmentInstanceChildren(child.sibling, childElements);
16641668
}
16651669

1666-
if (child.tag === HostComponent) {
1667-
childElements.add(child.stateNode);
1668-
return;
1670+
if (child.tag !== HostComponent) {
1671+
recursivelyGetFragmentInstanceChildren(child.child, childElements);
16691672
}
1670-
1671-
recursivelyGetFragmentInstanceChildren(child.child, childElements);
16721673
}
16731674

16741675
function normalizeListenerOptions(

packages/react-dom/src/__tests__/ReactDOMFragmentRefs-test.js

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,13 @@ describe('FragmentRefs', () => {
9696
const parentRef = React.createRef();
9797
const fragmentRef = React.createRef();
9898
const root = ReactDOMClient.createRoot(container);
99-
let focusedElement = null;
10099

101100
function Test() {
102101
return (
103102
<div ref={parentRef}>
104103
<Fragment ref={fragmentRef}>
105104
<div id="child-a" />
105+
<style>{`#child-c {}`}</style>
106106
<a id="child-b" href="/">
107107
B
108108
</a>
@@ -118,24 +118,10 @@ describe('FragmentRefs', () => {
118118
root.render(<Test />);
119119
});
120120

121-
// The test environment doesn't implement focus.
122-
// Mock it here, along with a naive focusable query so we can assert
123-
// that the first _focusable_ element is found.
124-
const focusableChildren = parentRef.current.querySelectorAll(
125-
'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])',
126-
);
127-
const focusMock = jest.spyOn(HTMLElement.prototype, 'focus');
128-
focusMock.mockImplementation(function () {
129-
if (Array.from(focusableChildren).includes(this)) {
130-
focusedElement = this.id;
131-
} else {
132-
return false;
133-
}
134-
});
135121
await act(() => {
136122
fragmentRef.current.focus();
137123
});
138-
expect(focusedElement).toEqual('child-b');
124+
expect(document.activeElement.id).toEqual('child-b');
139125
});
140126

141127
// @gate enableFragmentRefs

0 commit comments

Comments
 (0)