-
Notifications
You must be signed in to change notification settings - Fork 47k
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
[Fiber] Sync mount and unmount #8634
Changes from all commits
ffbb86b
3926a35
8090cf5
21f6d41
ce8c978
79f01b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,9 +67,10 @@ type HostContextDev = { | |
}; | ||
type HostContextProd = string; | ||
type HostContext = HostContextDev | HostContextProd; | ||
|
||
let eventsEnabled : ?boolean = null; | ||
let selectionInformation : ?mixed = null; | ||
type CommitInfo = { | ||
eventsEnabled: boolean, | ||
selectionInformation: mixed, | ||
}; | ||
|
||
var ELEMENT_NODE_TYPE = 1; | ||
var DOC_NODE_TYPE = 9; | ||
|
@@ -137,17 +138,18 @@ var DOMRenderer = ReactFiberReconciler({ | |
return getChildNamespace(parentNamespace, type); | ||
}, | ||
|
||
prepareForCommit() : void { | ||
eventsEnabled = ReactBrowserEventEmitter.isEnabled(); | ||
prepareForCommit() : CommitInfo { | ||
const eventsEnabled = ReactBrowserEventEmitter.isEnabled(); | ||
ReactBrowserEventEmitter.setEnabled(false); | ||
selectionInformation = ReactInputSelection.getSelectionInformation(); | ||
return { | ||
eventsEnabled, | ||
selectionInformation: ReactInputSelection.getSelectionInformation(), | ||
}; | ||
}, | ||
|
||
resetAfterCommit() : void { | ||
ReactInputSelection.restoreSelection(selectionInformation); | ||
selectionInformation = null; | ||
ReactBrowserEventEmitter.setEnabled(eventsEnabled); | ||
eventsEnabled = null; | ||
resetAfterCommit(commitInfo : CommitInfo) : void { | ||
ReactInputSelection.restoreSelection(commitInfo.selectionInformation); | ||
ReactBrowserEventEmitter.setEnabled(commitInfo.eventsEnabled); | ||
}, | ||
|
||
createInstance( | ||
|
@@ -322,9 +324,15 @@ function renderSubtreeIntoContainer(parentComponent : ?ReactComponent<any, any, | |
while (container.lastChild) { | ||
container.removeChild(container.lastChild); | ||
} | ||
root = container._reactRootContainer = DOMRenderer.createContainer(container); | ||
const newRoot = DOMRenderer.createContainer(container); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To satisfy Flow, which complains otherwise. I'm guessing because it doesn't know that |
||
root = container._reactRootContainer = newRoot; | ||
// Initial mount is always sync, even if we're in a batch. | ||
DOMRenderer.syncUpdates(() => { | ||
DOMRenderer.updateContainer(children, newRoot, parentComponent, callback); | ||
}); | ||
} else { | ||
DOMRenderer.updateContainer(children, root, parentComponent, callback); | ||
} | ||
DOMRenderer.updateContainer(children, root, parentComponent, callback); | ||
return DOMRenderer.getPublicRootInstance(root); | ||
} | ||
|
||
|
@@ -346,8 +354,11 @@ var ReactDOM = { | |
unmountComponentAtNode(container : DOMContainerElement) { | ||
warnAboutUnstableUse(); | ||
if (container._reactRootContainer) { | ||
return renderSubtreeIntoContainer(null, null, container, () => { | ||
container._reactRootContainer = null; | ||
// Unmount is always sync, even if we're in a batch. | ||
return DOMRenderer.syncUpdates(() => { | ||
return renderSubtreeIntoContainer(null, null, container, () => { | ||
container._reactRootContainer = null; | ||
}); | ||
}); | ||
} | ||
}, | ||
|
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.
FWIW this is how @spicyj wrote it originally but @sebmarkbage wanted to avoid the allocation.
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 see. I don't see a way to avoid it given that a sync update may occur inside
componentWillUnmount
. Unless we disallow sync updates there.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.
That actually might be a good idea... Interleaving commit phases could cause trouble.
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.
Since nested interleaved commits are broken anyway, can we revert this?
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.
Oops yes I meant to do that, forgot!