From 83cf21d8cfc6d3844988da75bdc4b5eaf5282521 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 17 Oct 2023 10:41:40 +0200 Subject: [PATCH] Merge pull request #15271 from overleaf/jpa-lazy-loading [web] lazy load big optional UI elements GitOrigin-RevId: 18d723c66834be3984b74c3c89cfb46e2fffbfc1 --- .../js/features/chat/components/chat-pane.jsx | 32 ++++++++++---- .../components/editor-left-menu-body.tsx | 17 ++++++++ .../components/editor-left-menu.tsx | 16 +++---- .../file-tree-modal-create-file-body.jsx | 11 ++++- .../history/components/history-content.tsx | 33 +++++++++++++++ .../history/components/history-root.tsx | 33 ++++----------- .../components/pdf-preview-pane.jsx | 12 +----- .../new-project-button-modal.tsx | 12 ++++-- .../share-project-modal-content.jsx | 21 ++++++++-- .../figure-modal/figure-modal-body.tsx | 2 +- .../components/figure-modal/figure-modal.tsx | 10 +++-- .../components/source-editor.tsx | 10 +---- ...oading-spinner.jsx => loading-spinner.tsx} | 19 +++++++++ .../frontend/stylesheets/_style_includes.less | 1 + .../frontend/stylesheets/app/editor/pdf.less | 8 ---- .../components/loading-spinner.less | 7 ++++ .../web/frontend/stylesheets/main-style.less | 1 + .../file-tree-modal-create-file.test.jsx | 42 +++++++++++-------- 18 files changed, 186 insertions(+), 101 deletions(-) create mode 100644 services/web/frontend/js/features/editor-left-menu/components/editor-left-menu-body.tsx create mode 100644 services/web/frontend/js/features/history/components/history-content.tsx rename services/web/frontend/js/shared/components/{loading-spinner.jsx => loading-spinner.tsx} (66%) create mode 100644 services/web/frontend/stylesheets/components/loading-spinner.less diff --git a/services/web/frontend/js/features/chat/components/chat-pane.jsx b/services/web/frontend/js/features/chat/components/chat-pane.jsx index 768fc9a76f..040a847f33 100644 --- a/services/web/frontend/js/features/chat/components/chat-pane.jsx +++ b/services/web/frontend/js/features/chat/components/chat-pane.jsx @@ -1,8 +1,7 @@ -import React, { useEffect } from 'react' +import React, { lazy, Suspense, useEffect, useState } from 'react' import PropTypes from 'prop-types' import { useTranslation } from 'react-i18next' -import MessageList from './message-list' import MessageInput from './message-input' import InfiniteScroll from './infinite-scroll' import ChatFallbackError from './chat-fallback-error' @@ -14,6 +13,8 @@ import { FetchError } from '../../../infrastructure/fetch-json' import { useChatContext } from '../context/chat-context' import LoadingSpinner from '../../../shared/components/loading-spinner' +const MessageList = lazy(() => import('./message-list')) + const ChatPane = React.memo(function ChatPane() { const { t } = useTranslation() @@ -48,6 +49,14 @@ const ChatPane = React.memo(function ChatPane() { 0 ) + // Keep the chat pane in the DOM to avoid resetting the form input and re-rendering MathJax content. + const [chatOpenedOnce, setChatOpenedOnce] = useState(chatIsOpen) + useEffect(() => { + if (chatIsOpen) { + setChatOpenedOnce(true) + } + }, [chatIsOpen]) + if (error) { // let user try recover from fetch errors if (error instanceof FetchError) { @@ -59,6 +68,9 @@ const ChatPane = React.memo(function ChatPane() { if (!user) { return null } + if (!chatOpenedOnce) { + return null + } return (