fix(GlassSurface): drop the duplicated resize effect - #1021
Open
noron12234 wants to merge 1 commit into
Open
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.
Contributor
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.
Comment on lines
182
to
184
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
Comment on lines
160
to
162
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
Comment on lines
138
to
140
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
Comment on lines
120
to
122
| useEffect(() => { | ||
| setTimeout(updateDisplacementMap, 0); | ||
| }, [width, height]); |
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.
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.