dillon1000/react
Commit
Browse files Improve validateNoRefAccessInRender
Rewrites the validation to not rely on the mutable range of functions to determine whether they are called or not, since the range can be extended for other reasons (they happen to reference a mutable value that is mutated later, even though the function isn't called during render). Instead we use the same approach as validateNoSetStateInRender, explicitly tracking references to function expressions that access refs, and checking if those function expressions appear to be called. This can have false negatives, as with the setState validation, but catches lots of obviously incorrect code without false positives.
Changed paths8 files
First-parent comparisoncompiler/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts ModifiedM compiler/packages/babel-plugin-react-forget/src/Validation/ValidateNoRefAccesInRender.ts ModifiedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-aliased-ref-in-callback-invoked-during-render-.expect.md AddedA compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-aliased-ref-in-callback-invoked-during-render-.js AddedM compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md ModifiedM compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.expect.md ModifiedM compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-set-and-read-ref-during-render.expect.md ModifiedM compiler/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-use-ref-added-to-dep-without-type-info.expect.md ModifiedPatch
Files changed
Rendering syntax-highlighted changes…