Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stronger react dom refreshed #7569

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
496 changes: 378 additions & 118 deletions lib/react-dom.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/jsx_intrinsics.builtin/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ var Str: string = 'str';
React.createElement('div', {}); // This is fine
React.createElement('bad', {}); // This is fine

<Div id={42} />; // This is fine
<Div nonexistentProp={42} />; // This is fine
12 changes: 6 additions & 6 deletions tests/react_16_3/react_16_3.exp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ References:
forwardRef.js:19:32
19| const badRef = React.createRef<HTMLDivElement>();
^^^^^^^^^^^^^^ [1]
<BUILTINS>/react-dom.js:290:22
290| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
^^^^^^^^^^^^^^^^^ [2]
<BUILTINS>/react-dom.js:290:44
290| button: ReactDOM$HTMLElementJSXIntrinsic<HTMLButtonElement, ReactDOM$HTMLElementProps>,
^^^^^^^^^^^^^^^^^ [2]
<BUILTINS>/react.js:240:6
240| ): {|current: null | T|};
^^^^^^^^^^^^^^^^^^^^^ [3]
Expand Down Expand Up @@ -72,9 +72,9 @@ References:
forwardRef.js:23:50
23| const _g = <FancyButton foo={3} ref={(x: null | HTMLDivElement) => x} />; // Incorrect ref type
^^^^^^^^^^^^^^ [3]
<BUILTINS>/react-dom.js:290:22
290| button: {instance: HTMLButtonElement, props: {children?: React$Node, [key: string]: any}},
^^^^^^^^^^^^^^^^^ [4]
<BUILTINS>/react-dom.js:290:44
290| button: ReactDOM$HTMLElementJSXIntrinsic<HTMLButtonElement, ReactDOM$HTMLElementProps>,
^^^^^^^^^^^^^^^^^ [4]


Error ---------------------------------------------------------------------------------------------- forwardRef.js:42:12
Expand Down
2 changes: 2 additions & 0 deletions tests/react_dom/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[options]
no_flowlib=false
8 changes: 8 additions & 0 deletions tests/react_dom/dangerouslySetInnerHTML.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// @flow

import React from "react";

<article dangerouslySetInnerHTML />; // Error: Expected object
<article dangerouslySetInnerHTML="<blink>Hello</blink>" />; // Error: Expected object
<article dangerouslySetInnerHTML={{ __html: "<blink>Hello</blink>" }} />; // OK
<article dangerouslySetInnerHTML={{ html: "<blink>Hello</blink>" }} />; // Error: Missing __html
19 changes: 19 additions & 0 deletions tests/react_dom/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

import React from "react";

<button onClick={() => {}} />; // OK
<input onChange="foo" />; // Error: Expected function
<div onMouseMoveCapture={(event: SyntheticMouseEvent<HTMLElement>) => {}} />; // OK
<textarea onKeyDown={(event: SyntheticMouseEvent<HTMLElement>) => {}} />; // Error: Wrong event type
<p onKeyPressCapture={(event: SyntheticKeyboardEvent<HTMLElement>) => {}} />; // OK
<iframe onLoad={event => { (event.currentTarget: HTMLIFrameElement); }} />; // OK
<canvas onFocus={(event: SyntheticEvent<HTMLElement>) => {}} />; // OK to annotate loosely
<a onMouseEnter={(event: SyntheticMouseEvent<HTMLElement>) => {}} />; // OK
<nav onMouseLeave={(event: SyntheticMouseEvent<HTMLElement>) => {}} />; // OK
<span onTouchTapCapture={(event: SyntheticUIEvent<HTMLElement>) => {}} />; // OK
<dialog onCompositionEnd={(event: SyntheticCompositionEvent<HTMLElement>) => {}} />; // OK
<article onBeforeInput={(event: SyntheticInputEvent<HTMLElement>) => {}} />; // OK
<img onMouseDown={event => {
const buttons: string = event.buttons; // Error: number ~> string
}} />
15 changes: 15 additions & 0 deletions tests/react_dom/props_boolean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow

import React from "react";

<span hidden />; // OK
<span hidden={false} />; // OK
<span hidden={null} />; // Error: Expected DOM boolean
<span hidden="true" />; // Error: Expected DOM boolean
<span hidden="false" />; // Error: Expected DOM boolean
<span hidden="" />; // Error: Expected DOM boolean
<span hidden="yes" />; // Error: Expected DOM boolean
<span hidden="hidden" />; // OK

// FIXME: Case-insensitive match should be allowed, per HTML spec
<span hidden="Hidden" />; // Currently an error
12 changes: 12 additions & 0 deletions tests/react_dom/props_booleanish_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow

import React from "react";

<div contentEditable />; // OK
<div contentEditable={false} />; // OK
<div contentEditable={null} />; // Error: Expected booleanish string
<div contentEditable="true" />; // OK
<div contentEditable="false" />; // OK
<div contentEditable="" />; // Error: Expected booleanish string
<div contentEditable="yes" />; // Error: Expected booleanish string
<div contentEditable="contentEditable" />; // Error: Expected booleanish string
15 changes: 15 additions & 0 deletions tests/react_dom/props_enum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// @flow

import React from "react";

<header dir />; // Error: Expected enum
<header dir="ltr" />; // OK
<header dir="rtl" />; // OK
<header dir="auto" />; // OK

// FIXME: Case-insensitive match should be allowed, per HTML spec
<header dir="Ltr" />; // currently an error

// These likely variants are special-cased
<header dir="LTR" />; // OK
<header dir="RTL" />; // OK
11 changes: 11 additions & 0 deletions tests/react_dom/props_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @flow

import React from "react";

<h1 tabIndex />; // Error: Expected number
<h1 tabIndex={-1} />; // OK
<h1 tabIndex={0} />; // OK
<h1 tabIndex={1} />; // OK

<h1 tabIndex="foo" />; // Error: Expected number
<h1 tabIndex="1" />; // Error: Expected number
6 changes: 6 additions & 0 deletions tests/react_dom/props_string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow

import React from "react";

<html id="root" />; // OK
<html id={42} />; // Error: Expected string
6 changes: 6 additions & 0 deletions tests/react_dom/props_style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow

import React from "react";

<footer style={{marginRight: "1em"}} />; // OK
<footer style="margin-right: 1em;" />; // Error: Expected object
Loading