diff --git a/src/typing/errors/error_message.ml b/src/typing/errors/error_message.ml index 99d7211787e..0a0860d6363 100644 --- a/src/typing/errors/error_message.ml +++ b/src/typing/errors/error_message.ml @@ -2868,7 +2868,8 @@ let defered_in_speculation = function | EAnyValueUsedAsType _ | EValueUsedAsType _ | EUnusedPromise _ - | EImplicitInstantiationUnderconstrainedError _ -> + | EImplicitInstantiationUnderconstrainedError _ + | EPropNotReadable { use_op = Frame (ReactDeepReadOnly _, _); _ } -> true | _ -> false diff --git a/tests/react_rules/dro.js b/tests/react_rules/dro.js index a1eb0813cb4..98243012f3d 100644 --- a/tests/react_rules/dro.js +++ b/tests/react_rules/dro.js @@ -140,3 +140,10 @@ component WriteToComponentProperty(x: {}) { declare const obj: React$Immutable; ({ n: obj.n }) as React$Immutable; // ok } + +component NonInterferenceWithInference(arr: Array) { + arr.sort((a, b) => { // only dro error + return 1; + }); + return null; +} diff --git a/tests/react_rules/react_rules.exp b/tests/react_rules/react_rules.exp index 16ec9906935..f4a4a85a040 100644 --- a/tests/react_rules/react_rules.exp +++ b/tests/react_rules/react_rules.exp @@ -412,23 +412,6 @@ References: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [1] -Error ----------------------------------------------------------------------------------------------------- dro.js:84:13 - -Cannot call `droarr.push` because number [1] is incompatible with unknown element of empty array [2] in array element of -array element. Arrays are invariantly typed. See -https://flow.org/en/docs/faq/#why-cant-i-pass-an-arraystring-to-a-function-that-takes-an-arraystring-number. -[incompatible-call] - - dro.js:84:13 - 84| droarr.push([]); // error - ^^ [2] - -References: - dro.js:83:51 - 83| declare const droarr: React$Immutable>>; - ^^^^^^ [1] - - Error ------------------------------------------------------------------------------------------------------ dro.js:85:1 Cannot call `droarr[0].push` because property `push` is not readable. Values annotated using `React.Immutable` [1] are @@ -677,6 +660,22 @@ References: ^^^^^ [1] +Error ----------------------------------------------------------------------------------------------------- dro.js:145:3 + +Cannot call `arr.sort` because property `sort` is not readable. React component properties [1] and their nested props +and elements cannot be written to. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#props). +[react-rule-unsafe-mutation] + + dro.js:145:3 + 145| arr.sort((a, b) => { // only dro error + ^^^^^^^^ + +References: + dro.js:144:40 + 144| component NonInterferenceWithInference(arr: Array) { + ^^^^^^^^^^^^^^^^^^ [1] + + Error ------------------------------------------------------------------- error.invalid-access-ref-during-render.js:8:17 Cannot read `current` from `ref` [1] because `ref` values may not be read during render.