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

perf(module:modal): call focus() on the next rendering frame to prevent frame drop #7293

Merged
merged 1 commit into from Apr 21, 2022

Conversation

arturovt
Copy link
Member

@arturovt arturovt commented Mar 4, 2022

Calling focus() on the element causes browsers to do re-layouts. This can been seen here:
https://gist.github.com/paulirish/5d52fb081b3570c81e3a#setting-focus
Microtasks are executed asynchronously, but within the current rendering frame. Using requestAnimationFrame
except of Promise.resolve basically unloads the current frame and calls focus() on the next rendering
frame, this prevent frame drops on slower devices when the modal is opened:

Flame graph

image

Reason

image

@zorro-bot
Copy link

zorro-bot bot commented Mar 4, 2022

This preview will be available after the AzureCI is passed.

@codecov
Copy link

codecov bot commented Mar 4, 2022

Codecov Report

Merging #7293 (8d7adbb) into master (d8ec154) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #7293   +/-   ##
=======================================
  Coverage   91.60%   91.60%           
=======================================
  Files         487      487           
  Lines       16006    16006           
  Branches     2604     2604           
=======================================
  Hits        14662    14662           
  Misses       1032     1032           
  Partials      312      312           
Impacted Files Coverage Δ
components/modal/modal-container.directive.ts 100.00% <100.00%> (+1.06%) ⬆️
components/tabs/tab-nav-bar.component.ts 87.23% <0.00%> (-0.71%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d8ec154...8d7adbb. Read the comment docs.

…vent frame drop

Calling `focus()` on the element causes browsers to do re-layouts. This can been seen here:
https://gist.github.com/paulirish/5d52fb081b3570c81e3a#setting-focus
Microtasks are executed asynchronously, but within the current rendering frame. Using `requestAnimationFrame`
except of `Promise.resolve` basically unloads the current frame and calls `focus()` on the next rendering
frame, this prevent frame drops on slower devices when the modal is opened.
@arturovt arturovt force-pushed the perf/modal-focus-next-frame branch from 3c92171 to 8d7adbb Compare March 12, 2022 23:06
Copy link
Member

@simplejason simplejason left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@simplejason simplejason merged commit 106d346 into NG-ZORRO:master Apr 21, 2022
@arturovt arturovt deleted the perf/modal-focus-next-frame branch April 30, 2022 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants