MDS and React

Copper Contributor

I've build a simple React component using UI Fabric. The  component is created in a static method from a class (TypeScript). Script is loaded from a Custom Action and made MDS compatible using RegisterModuleInit.

React & ReactDOM libraries are loaded suing SP.SOD.registerSOD and execFunc.


All this works perfectly fine on first page load. I could se the component rendered on the provided HTML element and visible in React developer tool.


But, when the page is reloaded (after visiting another one the the same site), the component does not work properly. It renders but no even (like a mouse click on a button) works.

Looking at React tool, the component is listed twice.


I've change my code as follow, trying to re-"attach" the already build component to the HTML element.

ReactDOM.render(this.component, theHTMLElement);

But React gives me an strange error: 

"Invariant Violation: ReactDOM.render(): Invalid component element. This may be caused by unintentionally loading two independent copies of React."


Any idea what I've implemented wrong ?


2 Replies

were you doing something similar to below:


if ("undefined" != typeof g_MinimalDownload && g_MinimalDownload) {
// Register script for MDS if possible
console.log('MDS enabled.');
RegisterModuleInit( _spPageContextInfo.webAbsoluteUrl + "/Style Library/MDS.js", RemoteManager_Inject); //MDS registration
console.log('Register Module after Init');
NonMDS(); //non MDS run
} else {
console.log('MDS not enabled.');

function NonMDS(){
console.log('Non MDS run...');
function RemoteManager_Inject() {
console.log('Remote Manager Inject');


Yes - something very similar and it works fine.


I've managed to "destroy" the old component (the one create from previous page load) by keeping a reference to the HTML element and calling ReactDOM.unmountComponentAtNode and then calling ReactDOM.render to build a new one.

I now have only instance of my component displayed in React DevTool but I still have issue with the evens. They are not triggered.

Digging in react.js...