-
Notifications
You must be signed in to change notification settings - Fork 47.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -275,4 +275,24 @@ describe('ReactIncrementalErrorHandling', () => { | |||
expect(ReactNoop.getChildren('e')).toEqual(null); | |||
expect(ReactNoop.getChildren('f')).toEqual(null); | |||
}); | |||
|
|||
it('restores environment state despite error during commit', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should both be imported as constants like these
react/src/renderers/shared/fiber/ReactFiberCommitWork.js
Lines 35 to 41 in e3131c1
const updateContainer = config.updateContainer; | |
const commitUpdate = config.commitUpdate; | |
const commitTextUpdate = config.commitTextUpdate; | |
const appendChild = config.appendChild; | |
const insertBefore = config.insertBefore; | |
const removeChild = config.removeChild; |
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
@@ -255,6 +270,8 @@ var ReactNoop = { | |||
|
|||
syncUpdates: NoopRenderer.syncUpdates, | |||
|
|||
isCommitting: () => isCommitting, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This caused a lint error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I turned off my precommit hook yesterday and forgot to reenable it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes Draft mostly work.
This makes Draft mostly work.