Add createEffectComponent, a thin r3f-native effect factory - #363
Merged
Conversation
Registers a postprocessing effect class as an r3f intrinsic and lets r3f's own reconciler handle args-driven reconstruction, live prop application, and disposal - no custom accessor scanning or fingerprinting. Also adds useLiveDefaults, the equivalent live-prop mechanism for effects that need real constructor args and can't use r3f's native reset-on-removal.
Removed redundant comments explaining ref behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
First PR in a stack that reworks how effects handle props (full context in later PRs - this one is purely additive and changes no existing behavior).
createEffectComponent, a thin factory that registers apostprocessingeffect class as an r3f intrinsic and lets r3f's own reconciler handle everything:args-driven reconstruction, live prop application (with the same Color/Vector coercion and reset-to-default on removal any r3f element gets), and disposal. No custom accessor scanning, no fingerprinting - only fits effects whose constructor works with zero arguments (new Effect()), since r3f's own reset-on-removal falls back to0otherwise.useLiveDefaults, the equivalent mechanism for effects that require real constructor args (scene/camera/etc.) and therefore can't usecreateEffectComponent. Snapshots each live-mutable property's constructor-time default once per instance, and only calls its setter when the resolved value actually changed - some setters have side effects beyond storing the value, so redundant calls aren't safe to make on every render.wrapEffect(for wrapping your own third-party effect classes) is untouched behaviorally - only itsEffectConstructortype moved to live increateEffectComponent.tsx, re-exported fromwrapEffect.tsxfor compatibility.Nothing in this PR is consumed by any existing effect yet - that happens in the following PRs in this stack.