This repository was archived by the owner on Feb 6, 2023. It is now read-only.
Commit d144883
try disabling 'blockSelectEvents' flag
Summary:
In the past Draft.js set a 'blockSelectEvents' flag on 'componentWillUpdate'
and unset it in 'componentDidUpdate'.
The reason for this, according to comments in the code, was that IE will fire
a 'selectionChange' event when we programmatically change the selection,
meaning it would trigger a new select event while we are in the middle of
updating.
**Edit:**
We found that the 'selection.addRange' was what triggered the stray `selectionchange` event in IE, for the record.[1] Thanks sophiebits for the tip about that.
When manually testing, I saw no bugs or inconsistencies introduced when the extra 'selectionchange' event fired in IE. The event would go into React, and yet it was never logged as triggering a handler in Draft.js.
So either that `selectionchange` event was not one that Draft.js. listened to, or React ignores/defers it because it's in the middle of a commit.
This diff does two things:
- Add logging to verify if we ever actually use the `blockSelectEvents` flag in practice. Is it actually blocking anything??? And if not, as I suspect, then;
- We can just remove it. This also removes it under a GK, so we can test on 50% employees first and see if they experience any bugs.
Lastly - I do want to add tests for this. It is error-prone and time consuming to set up and repeately do manual testing. Going to put together an outline of what I think the test should look like in a follow-up diff.
---
[1]: Here are the logs I recorded, for posterity
```
// inside of DraftEditor#focus
calling forceSelection
calling udpate with new editor state and new selection
componentWillUpdate fired!
This is where blockSelectEvents would be set to true~~~
a leaf is about to call setDraftEditorSelection
removing all ranges from the selection
calling range.setStart
**calling selection.addRange**
**React got an event of type topSelectionChange**
**window got an event of 'selectionchange'**
componentDidUpdate fired
This is where blockSelectEvents would be set to false~~~
React got an event of type topBlur
React got an event of type topFocus
Draft got an event of onFocus
Draft returned early because currentSelection already matches the updated selection
```
Reviewed By: sophiebits
Differential Revision: D6866079
fbshipit-source-id: 01034c6404df892224f5c18a45cba744a64d6e381 parent 558352c commit d144883
File tree
3 files changed
+18
-1
lines changed- src
- component
- base
- handlers/edit
- stubs
3 files changed
+18
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
381 | | - | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
382 | 386 | | |
383 | 387 | | |
384 | 388 | | |
| |||
414 | 418 | | |
415 | 419 | | |
416 | 420 | | |
| 421 | + | |
417 | 422 | | |
418 | 423 | | |
419 | 424 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
29 | 40 | | |
30 | 41 | | |
31 | 42 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
0 commit comments