Skip to content

Commit

Permalink
Update on "[compiler] Always error on async reassignments"
Browse files Browse the repository at this point in the history
Summary: Addresses the issue in #30109: any mutation of a local in an async function may occur after rendering has finished.

[ghstack-poisoned]
  • Loading branch information
mvitousek committed Jun 27, 2024
2 parents d8fba52 + 7a33e9c commit 5b63533
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import {
*/
export function validateLocalsNotReassignedAfterRender(fn: HIRFunction): void {
const contextVariables = new Set<IdentifierId>();
const reassignment = getContextReassignment(fn, contextVariables, false, false);
const reassignment = getContextReassignment(
fn,
contextVariables,
false,
false
);
if (reassignment !== null) {
CompilerError.throwInvalidReact({
reason:
Expand All @@ -38,7 +43,7 @@ function getContextReassignment(
fn: HIRFunction,
contextVariables: Set<IdentifierId>,
isFunctionExpression: boolean,
isAsync: boolean,
isAsync: boolean
): Place | null {
const reassigningFunctions = new Map<IdentifierId, Place>();
for (const [, block] of fn.body.blocks) {
Expand All @@ -51,7 +56,7 @@ function getContextReassignment(
value.loweredFunc.func,
contextVariables,
true,
isAsync || value.loweredFunc.func.async,
isAsync || value.loweredFunc.func.async
);
if (reassignment === null) {
// If the function itself doesn't reassign, does one of its dependencies?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function Component() {
local = newValue;
};
return reassignLocal;
}
};
const reassignLocal = mk_reassignlocal();
const onMount = (newValue) => {
reassignLocal("hello");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function Component() {
local = newValue;
};
return reassignLocal;
}
};
const reassignLocal = mk_reassignlocal();
const onMount = (newValue) => {
reassignLocal("hello");
Expand Down

0 comments on commit 5b63533

Please sign in to comment.