From 698de361783cc1a35b43b46af3c801eeaef3671e Mon Sep 17 00:00:00 2001 From: Bill Thornton Date: Fri, 4 Nov 2022 12:27:14 -0400 Subject: [PATCH] Optimize restoring views --- .../viewManager/ViewManagerPage.tsx | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/components/viewManager/ViewManagerPage.tsx b/src/components/viewManager/ViewManagerPage.tsx index cf4f4cdd48..563603e531 100644 --- a/src/components/viewManager/ViewManagerPage.tsx +++ b/src/components/viewManager/ViewManagerPage.tsx @@ -30,17 +30,9 @@ const ViewManagerPage: FunctionComponent = ({ 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 = ({ }; 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 + }); } }); };