refactor(wrapEffect): split out of util.tsx, support ref as a prop - #352
Open
kvvasuu wants to merge 1 commit into
Open
refactor(wrapEffect): split out of util.tsx, support ref as a prop#352kvvasuu wants to merge 1 commit into
kvvasuu wants to merge 1 commit into
Conversation
Pulls wrapEffect out of the general util grab-bag into its own module, and lets generated effect components accept ref as a regular prop (React 19) instead of having no ref support at all - previously none of the wrapEffect-based effects (Bloom, Vignette, HueSaturation, etc.) could be given a ref. Autofocus gets the same ref-as-prop treatment directly (it doesn't go through wrapEffect). Also fixes two related wrapEffect bugs: - The args memo fingerprinted props with JSON.stringify, which threw on circular references (textures, refs, and other three.js objects commonly hold one) - two independent reports (#333, #334) hit this on ordinary usage. Swapped in a cycle-safe stringify. - That fingerprint also called JSON.stringify's implicit toJSON, so THREE.Texture.toJSON() was re-encoding the whole image to a base64 data URL on every render just to compute a value that got discarded - measured ~39ms for a 512x512 texture. Fingerprinting now walks own properties directly and collapses typed arrays/buffers to an identity token instead. - ref itself wasn't destructured out of props, so it leaked into that same fingerprint; once mounted, ref.current pointed at the effect instance, so every render after the first fingerprinted a different value and silently rebuilt the instance in a loop. Adds a shared test harness (test-utils.tsx) used by this and later commits' test suites.
This was referenced Jul 29, 2026
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.
Pulls wrapEffect out of the general util grab-bag into its own module, and lets generated effect components accept ref as a regular prop (React 19) instead of having no ref support at all - previously none of the wrapEffect-based effects (Bloom, Vignette, HueSaturation, etc.) could be given a ref. Autofocus gets the same ref-as-prop treatment directly (it doesn't go through wrapEffect).
Also fixes two related wrapEffect bugs:
Adds a shared test harness (test-utils.tsx) used by this and later commits' test suites.