Comments (3)
I wonder why they are not using IntersectionObserver instead? It is not an intended use-case. Another problem I see from using this API for that is that the PerformanceObserver delivery of entries could be delayed, and this use-case would require quick delivery of the entries.
from layout-instability.
Hi! I'm the author of that long post, so I can give some additional background. As a quick note, I've updated it to no longer "recommend" using LayoutShift, and rather to point out that it may seem like a relevant choice, but that this discussion is also open about the intended use.
IntersectionObserver
is an interesting thought! At first my mind assumed that it wouldn't be useful, because we aren't looking to track when an element enters or leaves the viewport, but rather just when it changes positions within the viewport, where it most likely won't be intersecting anything or changing its intersection value at any point. We already have a more convenient solution to address scrolling and occlusion issues as described in that post by scoping where the ring gets rendered.
But, now that I think about it more, I think you are recommending that we could do something where the ring itself uses an IntersectionObserver
between its own current bounding box and the target element to see if the element has moved at all? That, I must admit, is not a possibility I had considered, but I'm very interested in trying this approach now.
Coming back to LayoutShift, this use case would indeed require timely delivery of entries (ideally within the same frame window with additional time to be able to update before the frame renders), and would ideally be able to track shifts at any granularity, even down to 1px or lower. As I mention at the end of that post, what this ring system really wants is a "subscribe to animation frame" API, rather than requesting one. LayoutShift (from initially skimming the spec), seemed like a potential match to provide that kind of subscription, but with this new information it is clearly not a great fit. I think clarifying the intended limitations would be useful to prevent that kind of misunderstanding as this API becomes more widely available.
from layout-instability.
One more reason to explicitly recommend against (and perhaps design against) the "layout changed, let's run some JS to update all our CSS and reposition these elements" use-case: we don't want to end up in a future where some fraction of websites depend on browsers supporting this feature in order to render properly.
Layout-shift is meant as a developer-facing feature for monitoring performance/user-experience; so I think we should make it clear that it's only meant to be used in a way where its implementation status is effectively undetectable to users. (This will ensure that we can safely deprecate & drop support for this API in the future, without breaking sites, once we've got a hypothetical better metric available and/or when this metric hypothetically becomes impractical for next-gen web engines to implement.)
from layout-instability.
Related Issues (20)
- CumulativeLayoutShift as WPT custom metric empty HOT 1
- Update CLS to window-based
- Specify layout shifts during drag HOT 2
- Explain expectations for content which shifts while fully obscured by other content (i.e. covered by a fixed position z-index overlay)
- Resolve confusion from equal previous/current rects
- Input Exclusion (lastInputTimestamp and hadRecentInput) should include certain interactions with Browser UI. HOT 1
- The definition of DCLS and CLS (non-normative) should mention ignoring shifts with hadRecentInput: True
- Broken references in Layout Instability API
- Clarify value of entry.name: empty string or "layout-shift"
- Clarify Input Exclusion and interactions across iframes
- Margin Collapsing can cause not-visible shifts to elements
- Timeout on CLS evaluation HOT 2
- Clarification about Hover causing layout shift HOT 2
- `content-visibility: auto;` makes CLS go bananas HOT 2
- Consider excluding user-scroll + scroll-anchor in the same frame from being penalized HOT 1
- What events trigger LayoutShift Performance Callback? HOT 2
- Starting point shift with countering transform change should be ignored HOT 1
- Change events should also trigger hadRecentInput
- ignore inline-direction shift in/out of view
- Case of sticky sidebars changing from absolute to fixed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from layout-instability.