Skip to content

refactor(wrapEffect): split out of util.tsx, support ref as a prop - #352

Open
kvvasuu wants to merge 1 commit into
fix/01-deps-and-toolingfrom
fix/02-wrapeffect-refactor
Open

refactor(wrapEffect): split out of util.tsx, support ref as a prop#352
kvvasuu wants to merge 1 commit into
fix/01-deps-and-toolingfrom
fix/02-wrapeffect-refactor

Conversation

@kvvasuu

@kvvasuu kvvasuu commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Stacked PR 2/6 — part of a split of #350 .
← based on #351 · → followed by #353

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 (fixes cyclic object value error in Scanline when using useRef #333, fixes circular structure to JSON --> starting at object with constructor #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.

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