mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
compiler: fix accidental propagation of function effects from StartMemoize/FinishMemoize
By default, React Compiler will skip compilation if it cannot preserve existing memoization. Ie, if the code has an existing `useMemo()` or `useCallback()` and the compiler cannot determine that it is safe to keep that memoization — or do even better — then we'll leave the code alone. The actual compilation doesn't use any hints from existing memo calls, this is purely to check and avoid regressing any specific memoization that developers may have already applied.
However, we were accidentally reporting some false-positive _validation_ errors due to the StartMemoize and FinishMemoize instructions that we emit to track where the memoization was in the source code. This is now fixed.
Fixes #29131
Fixes #29132
ghstack-source-id: 9f6b8dbc50
Pull Request resolved: https://github.com/facebook/react/pull/29154
This commit is contained in:
+2
-2
@@ -1611,14 +1611,14 @@ function inferBlock(
|
||||
val,
|
||||
Effect.Freeze,
|
||||
ValueReason.Other,
|
||||
functionEffects
|
||||
[]
|
||||
);
|
||||
} else {
|
||||
state.referenceAndRecordEffects(
|
||||
val,
|
||||
Effect.Read,
|
||||
ValueReason.Other,
|
||||
functionEffects
|
||||
[]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
## Input
|
||||
|
||||
```javascript
|
||||
// @validatePreserveExistingMemoizationGuarantees
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
let someGlobal = {};
|
||||
@@ -33,7 +34,7 @@ export const FIXTURE_ENTRYPOINT = {
|
||||
## Code
|
||||
|
||||
```javascript
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import { c as _c } from "react/compiler-runtime"; // @validatePreserveExistingMemoizationGuarantees
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
let someGlobal = {};
|
||||
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// @validatePreserveExistingMemoizationGuarantees
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
let someGlobal = {};
|
||||
|
||||
Reference in New Issue
Block a user