Skip to content

Commit 776d44a

Browse files
committed
[compiler] Prevent overriding a derivationEntry on effect mutation and instead update typeOfValue
1 parent 408b38e commit 776d44a

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,24 @@ function recordInstructionDerivations(
331331
case Effect.ConditionallyMutateIterator:
332332
case Effect.Mutate: {
333333
if (isMutable(instr, operand)) {
334-
context.derivationCache.addDerivationEntry(
335-
operand,
336-
sources,
337-
typeOfValue,
338-
);
334+
if (context.derivationCache.cache.has(operand.identifier.id)) {
335+
const operandMetadata = context.derivationCache.cache.get(
336+
operand.identifier.id,
337+
);
338+
339+
if (operandMetadata !== undefined) {
340+
operandMetadata.typeOfValue = joinValue(
341+
typeOfValue,
342+
operandMetadata.typeOfValue,
343+
);
344+
}
345+
} else {
346+
context.derivationCache.addDerivationEntry(
347+
operand,
348+
sources,
349+
typeOfValue,
350+
);
351+
}
339352
}
340353
break;
341354
}

0 commit comments

Comments
 (0)