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

@mcsf mcsf 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.

@mcsf mcsf added [Type] Bug An existing feature does not function as intended [Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable labels Aug 27, 2019
@ellatrix
Copy link
Member

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
Copy link
Contributor Author

mcsf 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
Copy link
Member

@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
Copy link
Contributor Author

mcsf 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 Compare August 27, 2019 14:04
@mcsf mcsf force-pushed the fix/request-idle-callback-fallback branch from a000229 to 97f4a57 Compare August 27, 2019 14:05
Copy link
Member

@ellatrix ellatrix left a comment

Choose a reason for hiding this comment

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

Sounds good

@mcsf mcsf merged commit 973448f into master Aug 27, 2019
@mcsf mcsf deleted the fix/request-idle-callback-fallback branch August 27, 2019 16:08
@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
Copy link
Contributor Author

mcsf commented Aug 27, 2019

Thanks for the quick review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Rich Text Related to the Rich Text component that allows developers to render a contenteditable [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants