Skip to content

Conversation

@jorge-cab
Copy link
Contributor

@jorge-cab jorge-cab commented Oct 24, 2025

Summary:
This makes the setState usage logic much more robust. We no longer rely on identifierName.

Now we track when a setState is loaded into a new promoted identifier variable and track this in a map setStateLoaded map.

For other types of instructions we consider the setState to be being used. In this case we record its usage into the setStateUsages map.

Test Plan:
We expect no changes in behavior for the current tests


Stack created with Sapling. Best reviewed with ReviewStack.

@meta-cla meta-cla bot added the CLA Signed label Oct 24, 2025
@jorge-cab jorge-cab force-pushed the pr34973 branch 2 times, most recently from 0b7e117 to 8e65f61 Compare October 27, 2025 23:57
@jorge-cab jorge-cab changed the title [compiler] Switch to track states by aliasing and id instead of identifier names [compiler] Switch to track setStates by aliasing and id instead of identifier names Oct 27, 2025
@jorge-cab jorge-cab force-pushed the pr34973 branch 4 times, most recently from d689084 to d237545 Compare October 28, 2025 01:22
@jorge-cab jorge-cab marked this pull request as ready for review October 28, 2025 01:23
@jorge-cab jorge-cab force-pushed the pr34973 branch 4 times, most recently from a44efd5 to 05025bd Compare October 28, 2025 22:51
…d instead update typeOfValue and fix infinite loops

Summary:
With this we are now comparing a snapshot of the derivationCache with the new changes every time we are done recording the derivations happening in the HIR.

We have to do this after recording everything since we still do some mutations on the cache when recording mutations.



Test Plan:
Test the following in playground:
```
// @validateNoDerivedComputationsInEffects_exp

function Component({ value }) {
  const [checked, setChecked] = useState('');

  useEffect(() => {
    setChecked(value === '' ? [] : value.split(','));
  }, [value]);

  return (
    <div>{checked}</div>
  )
}
```

This no longer causes an infinite loop.

Added a test case in the next PR in the stack
…or for `no-deriving-state-in-effects`

Summary:
Revamped the derivationCache graph.

This fixes a bunch of bugs where sometimes we fail to track from which props/state we derived values from.

Also, it is more intuitive and allows us to easily implement a Data Flow Tree.

We can print this tree which gives insight on how the data is derived and should facilitate error resolution in complicated components

Test Plan:
Added a test case where we were failing to track derivations. Also updated the test cases with the new error containing the data flow tree
…he error instead of throwing

Summary:
TSIA

Simple change to log errors in Pipeline.ts instead of throwing in the validation

Test Plan:
updated snap tests
…entifier names

Summary:
This makes the setState usage logic much more robust. We no longer rely on identifierName.

Now we track when a setState is loaded into a new promoted identifier variable and track this in a map `setStateLoaded` map.

For other types of instructions we consider the setState to be being used. In this case we record its usage into the `setStateUsages` map.



Test Plan:
We expect no changes in behavior for the current tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants