1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

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