File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
src/renderers/dom/shared/__tests__ Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -351,6 +351,26 @@ describe('ReactDOMServer', () => {
351
351
expect ( numClicks ) . toEqual ( 2 ) ;
352
352
} ) ;
353
353
354
+ // We have a polyfill for autoFocus on the client, but we intentionally don't
355
+ // want it to call focus() when hydrating because this can mess up existing
356
+ // focus before the JS has loaded.
357
+ it ( 'should emit autofocus on the server but not focus() when hydrating' , ( ) => {
358
+ var element = document . createElement ( 'div' ) ;
359
+ element . innerHTML = ReactDOMServer . renderToString (
360
+ < input autoFocus = { true } /> ,
361
+ ) ;
362
+ expect ( element . firstChild . autofocus ) . toBe ( true ) ;
363
+
364
+ // It should not be called on mount.
365
+ element . firstChild . focus = jest . fn ( ) ;
366
+ ReactDOM . hydrate ( < input autoFocus = { true } /> , element ) ;
367
+ expect ( element . firstChild . focus ) . not . toHaveBeenCalled ( ) ;
368
+
369
+ // Or during an update.
370
+ ReactDOM . render ( < input autoFocus = { true } /> , element ) ;
371
+ expect ( element . firstChild . focus ) . not . toHaveBeenCalled ( ) ;
372
+ } ) ;
373
+
354
374
it ( 'should throw with silly args' , ( ) => {
355
375
expect (
356
376
ReactDOMServer . renderToString . bind ( ReactDOMServer , { x : 123 } ) ,
You can’t perform that action at this time.
0 commit comments