Restore DOM selection and suppress events#8353
Conversation
|
I think that this just happens because we currently always reset the root. Otherwise it is usually to remove and insert the selected node. We can't keep doing that. We will instead use the append/remove child methods for the root too. However, even in that case this could be needed when a child that is selected is the one that needs to move. It needs to be fixed somewhere else though. I suspect we need something in the beginning and end of commitAllWork. |
sebmarkbage
left a comment
There was a problem hiding this comment.
We should do this in a way that covers all mutations in a commit instead of just the top which happens to work right now but won't soon.
9cf5de5 to
5d037a0
Compare
|
How about this? Sucks that I had to change all the other files. |
|
Can you add a test to ReactIncrementalErrorHandling verifying that environment state gets reset after an uncaught error? |
| return { | ||
| eventsEnabled, | ||
| selectionInformation: ReactInputSelection.getSelectionInformation(), | ||
| }; |
There was a problem hiding this comment.
Any reason we need to allocate instead of just mutating something in the closure here?
5d037a0 to
7838575
Compare
| if (!isCommitting) { | ||
| isCommitting = true; | ||
| config.prepareForCommit(); | ||
| } |
There was a problem hiding this comment.
It realized that this is not actually the correct behavior because if a life-cycle focuses a different thing we don't want to restore it back again.
Since these transaction wrappers are before the DOM ready queue and they execute in order it seems to me that the restore should actually happen before the life-cycles get invoked. So this whole block needs to move up to line 214.
| expect(ReactNoop.getChildren('f')).toEqual(null); | ||
| }); | ||
|
|
||
| it('restores environment state despite error during commit', () => { |
There was a problem hiding this comment.
Ideally we'd have a DOM specific test for this that tests the observable intent.
| break; | ||
| if (!isCommitting) { | ||
| isCommitting = true; | ||
| config.prepareForCommit(); |
There was a problem hiding this comment.
These should both be imported as constants like these
react/src/renderers/shared/fiber/ReactFiberCommitWork.js
Lines 35 to 41 in e3131c1
7838575 to
de9824c
Compare
|
Better, maybe. Now that we don't run user code before the restoration it's not totally clear to me that we need the try/catch but I guess it's safer to keep it. |
|
I added a test that fails if you restore state after lifecycles. |
|
It is still possible to fail if a ref callback which receives null is invoked. For example: |
|
Interestingly that case doesn't seem covered in the same way |
This makes Draft mostly work.
de9824c to
3448450
Compare
|
|
||
| syncUpdates: NoopRenderer.syncUpdates, | ||
|
|
||
| isCommitting: () => isCommitting, |
There was a problem hiding this comment.
I guess we can remove this now since we're not testing this.
| // something that could happen when manipulating DOM nodes (but is hard to | ||
| // deterministically force without relying intensely on React DOM | ||
| // implementation details) | ||
| var div = container.firstChild; |
There was a problem hiding this comment.
This caused a lint error.
There was a problem hiding this comment.
Sorry, I turned off my precommit hook yesterday and forgot to reenable it.
This makes Draft mostly work.
This makes Draft mostly work.