Optimize restoring views

This commit is contained in:
Bill Thornton 2022-11-04 12:27:14 -04:00
parent 20f8f4a745
commit 698de36178

View File

@ -30,17 +30,9 @@ const ViewManagerPage: FunctionComponent<ViewManagerPageProps> = ({
const location = useLocation();
useEffect(() => {
const loadPage = async () => {
const [ controllerFactory, viewHtml ] = await Promise.all([
import(/* webpackChunkName: "[request]" */ `../../controllers/${controller}`),
import(/* webpackChunkName: "[request]" */ `../../controllers/${view}`)
.then(html => globalize.translateHtml(html))
]);
const loadPage = () => {
const viewOptions = {
url: location.pathname + location.search,
controllerFactory,
view: viewHtml,
type,
state: location.state,
autoFocus: false,
@ -53,9 +45,19 @@ const ViewManagerPage: FunctionComponent<ViewManagerPageProps> = ({
};
viewManager.tryRestoreView(viewOptions)
.catch((result?: any) => {
.catch(async (result?: any) => {
if (!result || !result.cancelled) {
viewManager.loadView(viewOptions);
const [ controllerFactory, viewHtml ] = await Promise.all([
import(/* webpackChunkName: "[request]" */ `../../controllers/${controller}`),
import(/* webpackChunkName: "[request]" */ `../../controllers/${view}`)
.then(html => globalize.translateHtml(html))
]);
viewManager.loadView({
...viewOptions,
controllerFactory,
view: viewHtml
});
}
});
};