Skip to content

Add createEffectComponent, a thin r3f-native effect factory - #363

Open
kvvasuu wants to merge 2 commits into
v4from
pr1/foundation
Open

Add createEffectComponent, a thin r3f-native effect factory#363
kvvasuu wants to merge 2 commits into
v4from
pr1/foundation

Conversation

@kvvasuu

@kvvasuu kvvasuu commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

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).

  • Adds createEffectComponent, a thin factory that registers a postprocessing effect 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 to 0 otherwise.
  • Adds useLiveDefaults, the equivalent mechanism for effects that require real constructor args (scene/camera/etc.) and therefore can't use createEffectComponent. 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 its EffectConstructor type moved to live in createEffectComponent.tsx, re-exported from wrapEffect.tsx for compatibility.

Nothing in this PR is consumed by any existing effect yet - that happens in the following PRs in this stack.

kvvasuu added 2 commits August 5, 2026 20:38
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant