Skip to content

Commit ec26aff

Browse files
committed
Handle react 16’s async rendering
this is a workaround for react 16 since ReactDOM.render is not guaranteed to return the instance synchronously (especially if called within another component's lifecycle method eg: componentDidMount). see: facebook/react#10309 (comment) Test plan: * when rendered into canvas-lms using react16, it shouldn’t throw errors
1 parent bd31d6e commit ec26aff

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/plugin.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,23 @@ tinymce.create("tinymce.plugins.AccessibilityChecker", {
1111
const container = document.createElement("div")
1212
container.className = "tinymce-a11y-checker-container"
1313
document.body.appendChild(container)
14-
instance = ReactDOM.render(
14+
15+
ReactDOM.render(
1516
<Checker getBody={ed.getBody.bind(ed)} editor={ed} />,
16-
container
17+
container,
18+
function() {
19+
// this is a workaround for react 16 since ReactDOM.render is not
20+
// guaranteed to return the instance synchronously (especially if called
21+
// within another component's lifecycle method eg: componentDidMount). see:
22+
// https://github.com/facebook/react/issues/10309#issuecomment-318434635
23+
instance = this
24+
pendingInstanceCallbacks.forEach(cb => cb(instance))
25+
}
1726
)
18-
pendingInstanceCallbacks.forEach(cb => cb(instance))
1927

20-
ed.addCommand("openAccessibilityChecker", instance.check.bind(instance))
28+
ed.addCommand("openAccessibilityChecker", (...args) =>
29+
instance.check(...args)
30+
)
2131

2232
ed.addButton("check_a11y", {
2333
title: formatMessage("Check Accessibility"),

0 commit comments

Comments
 (0)