-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
RFC: @react-three/eslint-plugin rules #2701
Comments
Thanks for putting this up @CodyJasonBennett.
|
Correct me if any of this is wrong Cody.
For example it is not uncommon for someone to try calling function App() {
const ref = useRef()
// This will fail
const state = useThree()
// This will fail
useFrame(() => {
ref.current.rotation.y += .01
}, [])
return (
<Canvas>
<primitive ref={ref} />
</Canvas>
)}
He means the args props for three intrinsics. They are always an array in the order the params are ingested into the three class constructor. <mesh>
<boxGeometry args={[0.01, 0.01, 0.01]} />
</mesh> |
Oh of course, the args prop 😅. Thanks Krispy for the examples. I don't think we can effectively lint the hooks outside of canvas flow, it would be better for them to just throw if they were called... do they not do that today? |
Yup, they throw errors. |
no-clone-in-loop and no-new-in-loop have been merged: #2710 Picking up no-fast-state next. |
You should be able to update my initial comment if you want to track progress there. |
Ah yep! Will do next time. |
@CodyJasonBennett I'm thinking to remove no-hooks-outside-of-canvas and use-array-args from the RFC as they can be covered by dev runtime checks/TypeScript types. Is there anything there that would benefit from static analysis? |
Working here for the no-fast-state rule https://github.com/pmndrs/react-three-fiber/pull/2724/files#diff-68afedcc7ac7e2c951dd7e84dde7c1e1a55ae8e12d275d5ca88308a3c4dace87 For the use/start transition point can you give example code that would be OK? Also thinking about more rules from the pitfalls page:
When I get back to working on my r3f game I'll keep an eye out for patterns that would be useful to call out and lint. |
I wouldn't mention |
When we say safe polling case I assume we're talking about setting state with a guard, so even though there is state being set in the frame loop/set interval it doesn't matter because it isn't fast. Such as:
Is that on the money? If so for the first pass of the rule I wouldn't try to be too clever, pretty much if set state is guarded (without really checking what the guard is) we ignore the violation. |
Only concern would be with strictness (some may want to ban it completely for code style reasons), maybe this is something for a later rule or to be left in user-land. |
Could be a config option for sure. |
Aligning with our docs for general performance pitfalls and API usage around context (use R3F hooks within Canvas):
no-clone-in-frame-loop
: Prefer creating temporary objects in global space and copy rather than clone in hot paths. This should be restricted to three.js classes to avoid collisions. feat(eslint-plugin): add no-new-in-loop and no-clone-in-loop rules #2710no-fast-state
: Don't set state within loops or continuous events (startTransition
can be used if you must, this can be disabled for specific polling cases)prefer-useloader
: PreferuseLoader
for suspense and caching rather than callingLoader.load
orLoader.loadAsync
in an effect. This will de-dup resources on both the CPU and GPU and avoid later expensive runtime compilation.The text was updated successfully, but these errors were encountered: