dillon1000/react
Commit
Browse files [RFC] Improve validation against ref access in render
The goal of this PR is to improve ValidateNoRefAccessInRender to find function expressions which a) access refs and b) may be called during render. Currently we always allow ref access in any function expression, but that's obviously optimistic. For the approach, the observation is that we already have a system that tells us whether a function may get called — mutable range inference. So long as we consider a function "mutable", we'll infer a range for it, but the problem is that we don't currently view functions which depend on refs to be mutable. So here I'm doing ~~sort of~~ a hack to force function deps on refs to be treated as Effect.Capture. This is enough for the function to be considered mutable, for a mutable range to be assigned, and for us to detect that during ref validation. I don't love the hack, i'm open to other ideas!
Changed paths11 files
First-parent comparisoncompiler/forget/packages/babel-plugin-react-forget/src/Entrypoint/Pipeline.ts ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/HIR/ValidateNoRefAccesInRender.ts ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/Inference/AnalyseFunctions.ts ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-access-ref-during-render.expect.md ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-pass-ref-to-function.expect.md ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-set-and-read-ref-during-render.expect.md ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/error.invalid-use-ref-added-to-dep-without-type-info.expect.md ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-in-effect.expect.md ModifiedM compiler/forget/packages/babel-plugin-react-forget/src/__tests__/fixtures/compiler/ref-in-effect.js ModifiedA compiler/forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.expect.md AddedA compiler/forget/src/__tests__/fixtures/compiler/error.invalid-ref-in-callback-invoked-during-render.js AddedPatch
Files changed
Rendering syntax-highlighted changes…