Skip to content

Commit 5b63533

Browse files
committed
Update on "[compiler] Always error on async reassignments"
Summary: Addresses the issue in #30109: any mutation of a local in an async function may occur after rendering has finished. [ghstack-poisoned]
2 parents d8fba52 + 7a33e9c commit 5b63533

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

compiler/packages/babel-plugin-react-compiler/src/Validation/ValidateLocalsNotReassignedAfterRender.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
*/
2020
export function validateLocalsNotReassignedAfterRender(fn: HIRFunction): void {
2121
const contextVariables = new Set<IdentifierId>();
22-
const reassignment = getContextReassignment(fn, contextVariables, false, false);
22+
const reassignment = getContextReassignment(
23+
fn,
24+
contextVariables,
25+
false,
26+
false
27+
);
2328
if (reassignment !== null) {
2429
CompilerError.throwInvalidReact({
2530
reason:
@@ -38,7 +43,7 @@ function getContextReassignment(
3843
fn: HIRFunction,
3944
contextVariables: Set<IdentifierId>,
4045
isFunctionExpression: boolean,
41-
isAsync: boolean,
46+
isAsync: boolean
4247
): Place | null {
4348
const reassigningFunctions = new Map<IdentifierId, Place>();
4449
for (const [, block] of fn.body.blocks) {
@@ -51,7 +56,7 @@ function getContextReassignment(
5156
value.loweredFunc.func,
5257
contextVariables,
5358
true,
54-
isAsync || value.loweredFunc.func.async,
59+
isAsync || value.loweredFunc.func.async
5560
);
5661
if (reassignment === null) {
5762
// If the function itself doesn't reassign, does one of its dependencies?

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo.invalid-nested-function-reassign-local-variable-in-effect.expect.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Component() {
1111
local = newValue;
1212
};
1313
return reassignLocal;
14-
}
14+
};
1515
const reassignLocal = mk_reassignlocal();
1616
const onMount = (newValue) => {
1717
reassignLocal("hello");

compiler/packages/babel-plugin-react-compiler/src/__tests__/fixtures/compiler/todo.invalid-nested-function-reassign-local-variable-in-effect.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function Component() {
77
local = newValue;
88
};
99
return reassignLocal;
10-
}
10+
};
1111
const reassignLocal = mk_reassignlocal();
1212
const onMount = (newValue) => {
1313
reassignLocal("hello");

0 commit comments

Comments
 (0)