⚡ Bolt: Optimized GradientBlinds resize performance #50
Reference in New Issue
Block a user
Delete Branch "bolt-performance-gradient-blinds-resize-5528101139476827014"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
⚡ Bolt: Optimized GradientBlinds resize performance
💡 What:
Modified
GradientBlinds.tsxto useResizeObserverEntry.contentRectfor dimensions and defergetBoundingClientRect()torequestAnimationFrame.🎯 Why:
Calling
getBoundingClientRect()synchronously inside aResizeObservercallback forces a layout recalculation (thrashing) because the observer runs after layout but before paint.📊 Impact:
Reduces layout work during resize events. While visual impact is subtle, it prevents frame drops during window resizing, especially on lower-end devices.
🔬 Measurement:
Verified with
src/components/effects/GradientBlinds.test.tsxand manual code review. Existing tests pass.PR created automatically by Jules for task 5528101139476827014 started by @ragusa-it
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.
When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.
I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!
For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with
@jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!New to Jules? Learn more at jules.google/docs.
For security, I will only act on instructions from the user who triggered this task.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit:
7ecfd04f35ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
@@ -286,0 +285,4 @@if (entries && entries.length > 0) {const entry = entries[0];width = entry.contentRect.width;With
strict: trueintsconfig.json(which enablesnoImplicitAny),let width, height;is an implicitanyand will failpnpm exec tsc --noEmit(or any strict type check). This is a build-breaking regression introduced by the change; please add an explicitnumbertype or initialize the variables (e.g.,let width = 0, height = 0) so the file type-checks again.Useful? React with 👍 / 👎.
Pull request overview
This PR optimizes the resize performance of the GradientBlinds component by reducing layout thrashing during resize events. The optimization uses
ResizeObserverEntry.contentRectfor dimension calculations and defers thegetBoundingClientRect()call torequestAnimationFrame().Changes:
resizefunction to accept an optionalResizeObserverEntry[]parametercontentRect.widthandcontentRect.heightfor dimensionsgetBoundingClientRect()call torequestAnimationFrameto avoid forcing layout recalculation💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@@ -286,0 +295,4 @@}});} else {const rect = container.getBoundingClientRect();The requestAnimationFrame callback could execute after the component has unmounted. While there is a check for rendererRef.current, this doesn't prevent the container.getBoundingClientRect() call if the component unmounts between the check and the call. This could lead to accessing a detached DOM element.
Add a cleanup mechanism to cancel pending requestAnimationFrame callbacks, or store the RAF ID and cancel it in the useEffect cleanup function. Alternatively, add an additional check that the container is still in the document before calling getBoundingClientRect().
@@ -286,0 +296,4 @@});} else {const rect = container.getBoundingClientRect();rectRef.current = rect;The deferred update of rectRef.current can cause mouse position calculations to use stale position data. When a resize occurs, rectRef.current won't be updated until the next animation frame, but mouse events (via onPointerMove on lines 333-358 and the loop function on lines 360-409) may use the outdated rect during this gap. This can lead to incorrect mouse coordinate calculations, particularly noticeable during rapid resize operations.
Consider updating rectRef.current synchronously using contentRect properties (left, top can be derived from container.getBoundingClientRect() on initial call), or accept that mouse position calculations may be slightly off during resize until the next frame.
Pull request closed