feat: add reflow-free element measurement utility#271
Draft
feat: add reflow-free element measurement utility#271
Conversation
Introduces createElementMeasurer, a reflow-free measurement utility. Each frame, it attaches elements to an IntersectionObserver which delivers boundingClientRect asynchronously without triggering synchronous layout. Elements are immediately unobserved after measurement and re-observed on the next animation frame. - ElementMeasurement interface in types.ts - createElementMeasurer factory in utils/measure-element.ts Co-authored-by: Aiden Bai <[email protected]>
Co-authored-by: Aiden Bai <[email protected]>
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
- Rename variables for clarity (frameId → pendingFrameId, observer → intersectionObserver, isDisconnected → didDisconnect) - Extract cancelPendingFrame to eliminate repeated cancel pattern (DRY) - Remove unnecessary threshold array (re-observe each frame always triggers an initial entry, default threshold suffices) - Inline single-use observeTrackedElements into rAF callback - Rename onMeasure → onMeasurement for consistency - Rename MeasureElementHandle → ElementMeasurerHandle to match factory Co-authored-by: Aiden Bai <[email protected]>
Delete fetch-git-blame.ts (client-side fetcher) and vite-plugin-git-blame.ts (dev server middleware) — neither was imported or used anywhere in the codebase. Co-authored-by: Aiden Bai <[email protected]>
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.
Summary
Adds
createElementMeasurer, a utility for measuring DOM elements without triggering synchronous layout reflow. Also removes unused git blame code.How it works
The utility uses the
requestAnimationFrame+IntersectionObserverpattern:IntersectionObserverboundingClientRectdata without forcing synchronous layout/paintThis avoids the performance cost of
getBoundingClientRect()andgetComputedStyle()which force the browser to flush pending layout work synchronously.Changes
packages/react-grab/src/types.ts— AddedElementMeasurementinterface withx,y,width,height,isIntersecting, andintersectionRatiofieldspackages/react-grab/src/utils/measure-element.ts— NewcreateElementMeasurerfactory function that returns anobserve/unobserve/disconnecthandlepackages/react-grab/src/utils/fetch-git-blame.ts— Deleted (unused client-side git blame fetcher)packages/e2e-app/vite-plugin-git-blame.ts— Deleted (unused Vite dev server middleware for git blame)API
Summary by cubic
Adds
createElementMeasurerto measure DOM elements without triggering layout reflow, improvingreact-grabperformance. Also removes unused git blame utilities.New Features
createElementMeasurerinpackages/react-grab/src/utils/measure-element.tswithobserve,unobserve, anddisconnect.requestAnimationFrame+IntersectionObserverto readboundingClientRectasynchronously.ElementMeasurementinpackages/react-grab/src/types.tswithx,y,width,height,isIntersecting, andintersectionRatio.Refactors
packages/react-grab/src/utils/fetch-git-blame.tsandpackages/e2e-app/vite-plugin-git-blame.ts.Written for commit 26a0208. Summary will update on new commits.