Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/ui-utils/client/lib/openRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const getDomOfLoading = mem(function getDomOfLoading() {
});

function replaceCenterDomBy(dom) {
document.dispatchEvent(new CustomEvent('main-content-destroyed'));

const mainNode = document.querySelector('.main-content');
if (mainNode) {
for (const child of Array.from(mainNode.children)) {
Expand Down
33 changes: 28 additions & 5 deletions client/reactAdapters.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mountRoot = async () => {
}

const [
{ Suspense, createElement, lazy, useState },
{ Component, Fragment, Suspense, createElement, lazy, useLayoutEffect, useState },
{ render },
] = await Promise.all([
import('react'),
Expand All @@ -29,14 +29,30 @@ const mountRoot = async () => {

const LazyMeteorProvider = lazy(() => import('./providers/MeteorProvider'));

class Portals extends Component {
static getDerivedStateFromError = () => ({})

render = () => createElement(Fragment, {}, ...this.props.portals)
}

function AppRoot() {
const [portals, setPortals] = useState(() => Tracker.nonreactive(() => Array.from(portalsMap.values())));
invalidatePortals = () => {
setPortals(Array.from(portalsMap.values()));
};

useLayoutEffect(() => {
invalidatePortals = () => {
setPortals(Array.from(portalsMap.values()));
};
invalidatePortals();

return () => {
invalidatePortals = () => {};
};
}, []);

return createElement(Suspense, { fallback: null },
createElement(LazyMeteorProvider, {}, ...portals),
createElement(LazyMeteorProvider, {},
createElement(Portals, { portals }),
),
);
}

Expand Down Expand Up @@ -170,6 +186,13 @@ export const renderRouteComponent = (importFn, {
}

registerPortal(routeName, portal);

const handleMainContentDestroyed = () => {
unregisterPortal(routeName);
document.removeEventListener('main-content-destroyed', handleMainContentDestroyed);
};

document.addEventListener('main-content-destroyed', handleMainContentDestroyed);
});

Template[routeName] = blazeTemplate;
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.