Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronous layout-forcing APIs are not covered by any guideline #556

Open
xiaochengh opened this issue Feb 19, 2025 · 0 comments
Open

Synchronous layout-forcing APIs are not covered by any guideline #556

xiaochengh opened this issue Feb 19, 2025 · 0 comments

Comments

@xiaochengh
Copy link

(Noticed when reviewing w3ctag/design-reviews#1043)

There exists a class of JS APIs that queries the up-to-date layout result, and if we don't have that, synchronously forces a layout to recompute it. These APIs are known to be easily misused and cause layout thrashing.

Examples include:
Element.offset*, Document.elementFromPoint(), ...

The current guidelines do not provide a guidance for these known troublemakers:

  • Be synchronous when appropriate says a API should be synchronously if "the execution time is short and deterministic", but these APIs can incur a long execution time.

  • Design asynchronous APIs using Promises says an API might need to be asynchronous if "the user agent may need to do a significant amount of work on another thread, or in another process, before returning the result", but these APIs do a significant amount of work on the same thread.

@jyasskin jyasskin moved this to Performance in Key Topics Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Performance
Development

No branches or pull requests

1 participant