Don't emit autoFocus={false} attribute on the server (#11543)
Dan Abramov committed
Nov 13, 2017 at 15:22 UTC
afc5fab26ca95438ddbc07abd1099a2a9d4c4941
2 files changed
+18
-3
packages/react-dom/src/__tests__/ReactServerRendering-test.js
+15
@@ -382,6 +382,21 @@ describe('ReactDOMServer', () => {
382
expect(element.firstChild.focus).not.toHaveBeenCalled();
383
});
384
385
+ it('should not focus on either server or client with autofocus={false}', () => {
386
+ var element = document.createElement('div');
387
+ element.innerHTML = ReactDOMServer.renderToString(
388
+ <input autoFocus={false} />,
389
+ );
390
+ expect(element.firstChild.autofocus).toBe(false);
391
+
392
+ element.firstChild.focus = jest.fn();
393
+ ReactDOM.hydrate(<input autoFocus={false} />, element);
394
+ expect(element.firstChild.focus).not.toHaveBeenCalled();
395
+
396
+ ReactDOM.render(<input autoFocus={false} />, element);
397
+ expect(element.firstChild.focus).not.toHaveBeenCalled();
398
+ });
399
+
400
it('should throw with silly args', () => {
401
expect(
402
ReactDOMServer.renderToString.bind(ReactDOMServer, {x: 123}),
packages/react-dom/src/shared/HTMLDOMPropertyConfig.js
+3
-3
@@ -20,11 +20,11 @@ var HTMLDOMPropertyConfig = {
20
// name warnings.
21
Properties: {
22
allowFullScreen: HAS_BOOLEAN_VALUE,
23
- autoFocus: HAS_STRING_BOOLEAN_VALUE,
23
// specifies target context for links with `preload` type
24
async: HAS_BOOLEAN_VALUE,
26
- // autoFocus is polyfilled/normalized by AutoFocusUtils
27
- // autoFocus: HAS_BOOLEAN_VALUE,
25
+ // Note: there is a special case that prevents it from being written to the DOM
26
+ // on the client side because the browsers are inconsistent. Instead we call focus().
27
+ autoFocus: HAS_BOOLEAN_VALUE,
28
autoPlay: HAS_BOOLEAN_VALUE,
29
capture: HAS_OVERLOADED_BOOLEAN_VALUE,
30
checked: MUST_USE_PROPERTY | HAS_BOOLEAN_VALUE,