From 0217002cd03f34471518f7099eeb2ef1880783bf Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Tue, 27 Aug 2019 10:08:27 +0100 Subject: [PATCH 1/2] RichText: Fall back to requestAnimationFrame if no requestIdleCallback --- packages/block-editor/src/components/rich-text/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index fdf10696cbeda2..30416678b221d7 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -38,6 +38,8 @@ import FormatToolbar from './format-toolbar'; import { withBlockEditContext } from '../block-edit/context'; import { RemoveBrowserShortcuts } from './remove-browser-shortcuts'; +const requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame; + const wrapperClasses = 'editor-rich-text block-editor-rich-text'; const classes = 'editor-rich-text__editable block-editor-rich-text__editable'; @@ -301,7 +303,7 @@ class RichTextWrapper extends Component { * ensure all selection changes have been recorded. */ markAutomaticChange() { - window.requestIdleCallback( () => { + requestIdleCallback( () => { this.props.markAutomaticChange(); } ); } From 97f4a575097c9eee41662e129ecf4dc348c58310 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca Date: Tue, 27 Aug 2019 14:55:36 +0100 Subject: [PATCH 2/2] Fall back to setTimeout(_, 100) if no requestIdleCallback --- packages/block-editor/src/components/rich-text/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 30416678b221d7..25bbcf9b47955d 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -38,7 +38,10 @@ import FormatToolbar from './format-toolbar'; import { withBlockEditContext } from '../block-edit/context'; import { RemoveBrowserShortcuts } from './remove-browser-shortcuts'; -const requestIdleCallback = window.requestIdleCallback ? window.requestIdleCallback : window.requestAnimationFrame; +const requestIdleCallback = window.requestIdleCallback || + function fallbackRequestIdleCallback( fn ) { + window.setTimeout( fn, 100 ); + }; const wrapperClasses = 'editor-rich-text block-editor-rich-text'; const classes = 'editor-rich-text__editable block-editor-rich-text__editable';