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

RichText: Fall back to setTimeout if no requestIdleCallback #17213

Merged
merged 2 commits into from Aug 27, 2019

Conversation

@mcsf
Copy link
Contributor

commented Aug 27, 2019

Description

See #14776 (comment). If window.requestIdleCallback isn't available, fall back to window.requestAnimationFrame window.setTimeout. This approach is also used in priority-queue:

const requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame;

How has this been tested?

Make sure the behaviour introduced in #14776 is preserved both in environments that provide requestIdleCallback (e.g. Firefox) and those that don't (Safari).

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
@ellatrix

This comment has been minimized.

Copy link
Member

commented Aug 27, 2019

Oh, sorry, I saw usage when recording a performance profile, so I assumed it was fine. Unfortunately an animation frame won’t work I think. It will be too early if there’s multiple selection changes like the list input rule. Is there any other way to creat a fallback? Perhaps wait 100ms or so.

@mcsf

This comment has been minimized.

Copy link
Contributor Author

commented Aug 27, 2019

Perhaps wait 100ms or so.

@ellatrix: I trust your judgment on those heuristics. Would you rather implement that with just setTimeout, or build something atop requestAnimationFrame?

@ellatrix

This comment has been minimized.

Copy link
Member

commented Aug 27, 2019

@mcsf not sure if it matters or what the difference may be. The important thing is that all changes have been completed and all selection changes are done. That’s why I picked an idle period. This is also fine from a UX point of view cause you cannot realize an automatic change happened before an idle period to undo it. I think 100 ms or even less is fine to replace this, I don’t think it really matters how unless there’s some way to detect idleness. The nice thing about idleness is that you’re sure all work is done, no matter how slow the browser is.

@mcsf

This comment has been minimized.

Copy link
Contributor Author

commented Aug 27, 2019

I think 100 ms or even less is fine to replace this, I don’t think it really matters how unless there’s some way to detect idleness. The nice thing about idleness is that you’re sure all work is done, no matter how slow the browser is.

Yeah, idleness is a lot nicer, but I'm fine with the trade-off that it might not be as smooth on browsers that haven't implemented requestIdleCallback yet. I've pushed another commit so that the fallback uses setTimeout(_, 100) instead of requestAnimationFrame. What do you think, @ellatrix?

@mcsf mcsf force-pushed the fix/request-idle-callback-fallback branch from 4bc91a5 to a000229 Aug 27, 2019
@mcsf mcsf force-pushed the fix/request-idle-callback-fallback branch from a000229 to 97f4a57 Aug 27, 2019
Copy link
Member

left a comment

Sounds good

@mcsf mcsf merged commit 973448f into master Aug 27, 2019
2 checks passed
2 checks passed
pull-request-automation
Details
Travis CI - Pull Request Build Passed
Details
@mcsf mcsf deleted the fix/request-idle-callback-fallback branch Aug 27, 2019
@mcsf mcsf changed the title RichText: Fall back to requestAnimationFrame if no requestIdleCallback RichText: Fall back to setTimeout if no requestIdleCallback Aug 27, 2019
@mcsf

This comment has been minimized.

Copy link
Contributor Author

commented Aug 27, 2019

Thanks for the quick review!

@gziolo gziolo added this to the Gutenberg 6.5 milestone Aug 30, 2019
dd32 pushed a commit to dd32/gutenberg that referenced this pull request Sep 27, 2019
…s#17213)

* RichText: Fall back to requestAnimationFrame if no requestIdleCallback
* Fall back to setTimeout(_, 100) if no requestIdleCallback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.