Skip to content

Commit

Permalink
Opt-in to the React 18 root API
Browse files Browse the repository at this point in the history
  • Loading branch information
p2edwards committed Jul 2, 2024
1 parent 66c8b59 commit 30862c5
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions jsapp/js/main.es6
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@
* plus it is the file that is handling the root rendering.
*/

require('jquery-ui/ui/widgets/sortable');
import 'jquery-ui/ui/widgets/sortable';
import moment from 'moment';
import AllRoutes from 'js/router/allRoutes';
import RegistrationPasswordApp from './registrationPasswordApp';
import {AppContainer} from 'react-hot-loader';
import React from 'react';
import {Cookies} from 'react-cookie';
import {render} from 'react-dom';
import {createRoot} from 'react-dom/client';
import * as Sentry from '@sentry/react';
import {csrfSafeMethod, currentLang} from 'utils';
require('../scss/main.scss');
import '../scss/main.scss';
import Modal from 'react-modal';

let sentryDsnEl = document.head.querySelector('meta[name=sentry-dsn]');
const sentryDsnEl = document.head.querySelector('meta[name=sentry-dsn]');
if (sentryDsnEl !== null) {
Sentry.init({
dsn: sentryDsnEl.content,
tracesSampleRate: 0.0,
sendClientReports: false,
autoSessionTracking: false,
})
});
window.Raven = Sentry; // Legacy use (formbuilder)
/*
In TS files, it's safe to do
Expand Down Expand Up @@ -86,22 +86,21 @@ if (document.head.querySelector('meta[name=kpi-root-path]')) {
Modal.setAppElement('#kpiapp');
return $d.get(0);
})();

render(<AllRoutes />, el);
const root = createRoot(el);
root.render(<AllRoutes />);

if (module.hot) {
module.hot.accept('js/app', () => {
const AllRoutes = require('js/app').default;
render(
root.render(
<AppContainer>
<AllRoutes />
</AppContainer>,
el
</AppContainer>
);
});
}
} else {
console.error('no kpi-root-path meta tag set. skipping react-router init');
console.warn('no kpi-root-path meta tag set. skipping react-router init');
}

// Handles rendering a small app in the registration form
Expand All @@ -110,11 +109,11 @@ document.addEventListener('DOMContentLoaded', () => {
'registration-password-app'
);
if (registrationPasswordAppEl) {
render(
const root = createRoot(registrationPasswordAppEl);
root.render(
<AppContainer>
<RegistrationPasswordApp />
</AppContainer>,
registrationPasswordAppEl
</AppContainer>
);
}
});

0 comments on commit 30862c5

Please sign in to comment.