Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[compiler] Validate against setState in useMemo (resubmit of #30552) #30583

Merged
merged 1 commit into from
Aug 2, 2024

Commits on Aug 2, 2024

  1. [compiler] Validate against setState in useMemo (resubmit of #30552)

    ghstack failed to land #30552 properly, resubmitting
    
    Developers sometimes use `useMemo()` as a way to conditionally execute code, including conditionally calling setState. However, the compiler may remove existing useMemo calls if they are not necessary, which _should_ always be a safe optimization. If the useMemo has side effects (eg sets state), then this isn't safe.
    
    This PR improves ValidateNoSetStateInRender to disallow any setState in useMemo (even if it's conditional), expanding on the previous check for unconditional setState in render. Note that the approach uses the StartMemoize/FinishMemoize instructions added in DropManualMemo to know whether a particular setState call is within a useMemo or not. This means enabling the validation in DropManualMemo when the setState validation is enabled, but that's fine since that validation is on everywhere by default (_except_ for in fixtures, which we have a todo for)
    
    [ghstack-poisoned]
    josephsavona committed Aug 2, 2024
    Configuration menu
    Copy the full SHA
    dfd4161 View commit details
    Browse the repository at this point in the history