Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function parseStackTraceFromChromeStack(
return parsedFrames;
}

const firefoxFrameRegExp = /^((?:.*".+")?[^@]*)@(.+):(\d+):(\d+)$/;
const firefoxFrameRegExp = /^([^@"]*(?:"[^"]*"[^@"]*)*)@(.+):(\d+):(\d+)$/;
function parseStackTraceFromFirefoxStack(
stack: string,
skipFrames: number,
Expand Down Expand Up @@ -94,7 +94,7 @@ function parseStackTraceFromFirefoxStack(
return parsedFrames;
}

const CHROME_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
const CHROME_STACK_REGEXP = /^\s*at /m;
export function parseStackTraceFromString(
stack: string,
skipFrames: number,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-dom-bindings/src/client/ReactFiberConfigDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ export function finalizeInitialChildren(
): boolean {
setInitialProperties(domElement, type, props);
switch (type) {
case 'a':
case 'button':
case 'input':
case 'select':
Expand Down Expand Up @@ -846,12 +847,14 @@ export function commitMount(
// there are also other cases when this might happen (such as patching
// up text content during hydration mismatch). So we'll check this again.
switch (type) {
case 'a':
case 'button':
case 'input':
case 'select':
case 'textarea':
if (newProps.autoFocus) {
((domElement: any):
| HTMLAnchorElement
| HTMLButtonElement
| HTMLInputElement
| HTMLSelectElement
Expand Down
34 changes: 34 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOM-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,40 @@ describe('ReactDOM', () => {
}
});

it('calls focus() on autoFocus anchor elements after they have been mounted to the DOM', async () => {
const originalFocus = HTMLElement.prototype.focus;

try {
let focusedElement;
let anchorFocusedAfterMount = false;

HTMLElement.prototype.focus = function () {
focusedElement = this;
anchorFocusedAfterMount = !!this.parentNode;
};

const container = document.createElement('div');
document.body.appendChild(container);
const root = ReactDOMClient.createRoot(container);
await act(() => {
root.render(
<div>
<h1>Auto-focus Test</h1>
<a href="https://react.dev" autoFocus={true}>
Link
</a>
<p>The above anchor should be focused after mount.</p>
</div>,
);
});

expect(anchorFocusedAfterMount).toBe(true);
expect(focusedElement.tagName).toBe('A');
} finally {
HTMLElement.prototype.focus = originalFocus;
}
});

it("shouldn't fire duplicate event handler while handling other nested dispatch", async () => {
const actual = [];

Expand Down