fix(GlassSurface): drop the duplicated resize effect - #1021
Conversation
The component registers the same effect twice — byte-identical bodies, both creating a ResizeObserver on containerRef and calling updateDisplacementMap. So every instance runs two observers on one element and rebuilds the SVG displacement map twice on every resize. Removes the second copy. All four variants carry the same duplication.
There was a problem hiding this comment.
Pull request overview
This pull request removes a byte-identical, duplicated ResizeObserver useEffect from the GlassSurface component implementations so each instance registers only one observer and performs a single displacement-map regeneration per resize.
Changes:
- Removed the duplicated
ResizeObservereffect in the TS + Tailwind variant. - Removed the duplicated
ResizeObservereffect in the TS + CSS variant. - Removed the duplicated
ResizeObservereffect in the JS + Tailwind and JS + CSS variants.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| src/ts-tailwind/Components/GlassSurface/GlassSurface.tsx | Removes the duplicated ResizeObserver useEffect block. |
| src/ts-default/Components/GlassSurface/GlassSurface.tsx | Removes the duplicated ResizeObserver useEffect block. |
| src/tailwind/Components/GlassSurface/GlassSurface.jsx | Removes the duplicated ResizeObserver useEffect block. |
| src/content/Components/GlassSurface/GlassSurface.jsx | Removes the duplicated ResizeObserver useEffect block. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
public/r/*.json embeds the component source verbatim, and that is what the jsrepo CLI actually writes into a user's project. Fixing only the .tsx/.jsx files left the shipped payload with both copies of the effect, so installs would still get two ResizeObservers per instance. Regenerated with `npm run registry:build`; the four GlassSurface entries are the only ones that change.
|
Good catch, the review is right. Pushed Same gap applied to my three other open PRs, so I have pushed the rebuilt artifacts there too: #1018, #1020, #1022. |
The problem
GlassSurfaceregisters the same effect twice. Not similar — byte-identical:So every instance runs two
ResizeObservers on the same element, and each resize regenerates the SVG displacement map twice — that's afeImagedata-URI rebuild plusfeDisplacementMapattribute writes, done twice for nothing.Measurement
One
<GlassSurface>in a stock Vite React app, withResizeObserverwrapped to count constructions:mainStill renders identically after the change — same three
feDisplacementMapnodes, no console errors, and resizes still update the filter (verified by resizing twice via a width prop).Scope
All four variants carry the same duplication, so all four are fixed:
content,tailwind,ts-default,ts-tailwind. The diff is deletion only — 56 lines removed, nothing added.Verification
npx tsc --noEmit: no new errors (zero mentioning GlassSurface).npx prettier --checkclean on all four files.npx vite buildpasses.Found while scanning for effects that create a resource without releasing it; this one turned up because the duplicate made the same file report the same pattern twice.