adobe / react-webcomponent

This projects automates the wrapping of a React component in a CustomElement.
Apache License 2.0
105 stars 19 forks source link

Fix possible exception with ReactDOM.unmountComponentAtNode #24

Closed herzog31 closed 4 years ago

herzog31 commented 4 years ago

Description

This PR fixes a potential exception with the ReactDOM.unmountComponentAtNode method call when the result of _rootShadows.get(this) is undefined.

I could consistently reproduce the issue in the context of the AEM editor, but couldn't find a minimal example to demonstrate the issue.

react-dom.development.js:27628 Uncaught Error: unmountComponentAtNode(...): Target container is not a DOM element.
    at Object.unmountComponentAtNode (react-dom.development.js:27628)

How Has This Been Tested?

Manual testing.

Types of changes

Checklist:

alexmirea commented 4 years ago

@herzog31 Thanks for spotting this! Yes if the node is undefined, the call to unmount from react will throw an error. https://github.com/facebook/react/blob/master/packages/react-dom/src/__tests__/ReactMount-test.js#L30 But I would still check if there isn't some code that destroys the element somehow. The creation phase shouldn't leave the reference unassigned in the map. If you can reproduce it somehow to test it, I think that would be good.