Repository: facebook/react
File: compiler/packages/babel-plugin-react-compiler/src/Inference/InferEffectDependencies.ts (TypeScript)

Code before:
            if (scopeInfo.pruned || !scopeInfo.hasSingleInstr) {
              /**
               * TODO: retry pipeline that ensures effect function expressions
               * are placed into their own scope
               */
              CompilerError.throwTodo({
                reason:
                  '[InferEffectDependencies] Expected effect function to have non-pruned scope and its scope to have exactly one instruction',
                loc: fnExpr.loc,
              });
            }

            /**
             * Step 1: push dependencies to the effect deps array
             *
             * Note that it's invalid to prune all non-reactive deps in this pass, see
             * the `infer-effect-deps/pruned-nonreactive-obj` fixture for an
             * explanation.
             */
            for (const dep of scopeInfo.deps) {
              if (
                (isUseRefType(dep.identifier) ||
                  isSetStateType(dep.identifier)) &&
                !reactiveIds.has(dep.identifier.id)
              ) {
                // exclude non-reactive hook results, which will never be in a memo block
                continue;
              }

              const {place, instructions} = writeDependencyToInstructions(
                dep,
                reactiveIds.has(dep.identifier.id),
                fn.env,
                fnExpr.loc,
              );
              newInstructions.push(...instructions);
              effectDeps.push(place);
            }

            newInstructions.push({
              id: makeInstructionId(0),
              loc: GeneratedSource,
              lvalue: {...depsPlace, effect: Effect.Mutate},
              value: deps,
            });

            // Step 2: push the inferred deps array as an argument of the useEffect
            value.args.push({...depsPlace, effect: Effect.Freeze});
            rewriteInstrs.set(instr.id, newInstructions);
            fn.env.inferredEffectLocations.add(callee.loc);
          } else if (loadGlobals.has(value.args[0].identifier.id)) {

Review comment (suggestion):
Ahh makes sense, fire is different than setState / refs in that we always codegen the `useFire` hook call, so there is no "reactive reference to non-reactive values" issue (e.g. `props.cond ? ref1 : ref2`)

Code after:
            });
            if (scopeInfo.pruned || !scopeInfo.hasSingleInstr) {
              /**
               * TODO: retry pipeline that ensures effect function expressions
               * are placed into their own scope
               */
              CompilerError.throwTodo({
                reason:
                  '[InferEffectDependencies] Expected effect function to have non-pruned scope and its scope to have exactly one instruction',
                loc: fnExpr.loc,
              });
            }

            /**
             * Step 1: push dependencies to the effect deps array
             *
             * Note that it's invalid to prune all non-reactive deps in this pass, see
             * the `infer-effect-deps/pruned-nonreactive-obj` fixture for an
             * explanation.
             */
            for (const dep of scopeInfo.deps) {
              if (
                ((isUseRefType(dep.identifier) ||
                  isSetStateType(dep.identifier)) &&
                  !reactiveIds.has(dep.identifier.id)) ||
                isFireFunctionType(dep.identifier)
              ) {
                // exclude non-reactive hook results, which will never be in a memo block
                continue;
              }

              const {place, instructions} = writeDependencyToInstructions(
                dep,
                reactiveIds.has(dep.identifier.id),
                fn.env,
                fnExpr.loc,
              );
              newInstructions.push(...instructions);
              effectDeps.push(place);
            }

            newInstructions.push({
              id: makeInstructionId(0),
              loc: GeneratedSource,
              lvalue: {...depsPlace, effect: Effect.Mutate},
              value: deps,
            });

            // Step 2: push the inferred deps array as an argument of the useEffect
            value.args.push({...depsPlace, effect: Effect.Freeze});
            rewriteInstrs.set(instr.id, newInstructions);