Skip to content

Commit eb2bb38

Browse files
authored
Fix bug where checker could be opened twice and delete nodes (#138)
* Fix bug where checker could be opened twice and delete nodes Prevents opening the checker while it is already open, which could cause nodes to be deleted closes MAT-1106 Test Plan: - Open an RCE and create content that causes an a11y violation - Click the a11y checker icon to open the a11y checker - Check the box to apply formatting changes - Click the a11y checker icon to Open the a11y checker again (without closing it) - Verify RCE content is not changed, RCE can be edited and used as normal - Verify a11y checker can be opened again, used as normal * Update version and changelog * Update CHANGELOG for real
1 parent 3cd72ce commit eb2bb38

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
## [4.2.3] - 2023-01-30
10+
## [4.1.4] - 2023-02-14
11+
12+
- Fixed a bug where the a11y checker could be opened twice and cause
13+
content to become deleted
14+
15+
## [4.1.3] - 2023-01-30
1116

1217
- Change the violation highlight from an absolutely positioned blue box
1318
to an outline created with just CSS

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "tinymce-a11y-checker",
3-
"version": "4.1.3",
3+
"version": "4.1.4",
44
"description": "An accessibility checker plugin for TinyMCE.",
55
"main": "lib/plugin.js",
66
"module": "es/plugin.js",

src/components/checker.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ export default class Checker extends React.Component {
5353

5454
componentDidMount() {
5555
this.props.editor.on("Remove", (editor) => {
56-
this.setState({ open: false })
56+
this.setState({ open: false }, () => {
57+
this.props.onClose()
58+
})
5759
})
5860
}
5961

@@ -282,7 +284,9 @@ export default class Checker extends React.Component {
282284
handleClose() {
283285
this.onLeaveError()
284286
clearIndicators(this.props.editor.dom.doc)
285-
this.setState({ open: false })
287+
this.setState({ open: false }, () => {
288+
this.props.onClose()
289+
})
286290
}
287291

288292
render() {

src/plugin.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Checker from "./components/checker"
44
import formatMessage from "./format-message"
55
import checkNode from "./node-checker"
66

7+
let isCheckerOpen = false
78
let instance
89
const pendingInstanceCallbacks = []
910
const container = document.createElement("div")
@@ -16,25 +17,29 @@ tinymce.create("tinymce.plugins.AccessibilityChecker", {
1617
ui,
1718
{ done, config, additionalRules, mountNode }
1819
) {
19-
ReactDOM.render(
20-
<Checker
21-
getBody={ed.getBody.bind(ed)}
22-
editor={ed}
23-
additionalRules={additionalRules}
24-
mountNode={mountNode}
25-
/>,
26-
container,
27-
function () {
28-
// this is a workaround for react 16 since ReactDOM.render is not
29-
// guaranteed to return the instance synchronously (especially if called
30-
// within another component's lifecycle method eg: componentDidMount). see:
31-
// https://github.com/facebook/react/issues/10309#issuecomment-318434635
32-
instance = this
33-
if (config) getInstance(instance => instance.setConfig(config))
34-
pendingInstanceCallbacks.forEach(cb => cb(instance))
35-
instance.check(done)
36-
}
37-
)
20+
if (!isCheckerOpen) {
21+
ReactDOM.render(
22+
<Checker
23+
getBody={ed.getBody.bind(ed)}
24+
editor={ed}
25+
additionalRules={additionalRules}
26+
mountNode={mountNode}
27+
onClose={() => isCheckerOpen = false}
28+
/>,
29+
container,
30+
function () {
31+
// this is a workaround for react 16 since ReactDOM.render is not
32+
// guaranteed to return the instance synchronously (especially if called
33+
// within another component's lifecycle method eg: componentDidMount). see:
34+
// https://github.com/facebook/react/issues/10309#issuecomment-318434635
35+
instance = this
36+
if (config) getInstance(instance => instance.setConfig(config))
37+
pendingInstanceCallbacks.forEach(cb => cb(instance))
38+
instance.check(done)
39+
}
40+
)
41+
isCheckerOpen = true
42+
}
3843
})
3944

4045
ed.addCommand("checkAccessibility", function (

0 commit comments

Comments
 (0)