diff --git a/package-lock.json b/package-lock.json index 45d72c1..67d22c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -29,7 +29,7 @@ "react": "^16.9.0", "react-dnd": "^14.0.5", "react-dnd-html5-backend": "^14.1.0", - "react-doc-viewer": "git+https://git@github.com/warpdesign/react-doc-viewer.git#release", + "react-doc-viewer": "github:warpdesign/react-doc-viewer#release", "react-dom": "^16.9.0", "react-i18next": "^12.0.0", "react-virtual": "^2.10.4" @@ -12154,7 +12154,7 @@ }, "node_modules/react-doc-viewer": { "version": "1.14.1", - "resolved": "git+https://git@github.com/warpdesign/react-doc-viewer.git#3a8bf265674e9920c47012acd313efc2516c6efe", + "resolved": "git+https://git@github.com/warpdesign/react-doc-viewer.git#e2c6ae562172360e052b9a462bb90fa5879e7d1a", "dependencies": { "@types/mustache": "^4.2.3", "@types/papaparse": "^5.3.9", diff --git a/package.json b/package.json index b12cb3d..a0b6e78 100644 --- a/package.json +++ b/package.json @@ -138,7 +138,7 @@ "react": "^16.9.0", "react-dnd": "^14.0.5", "react-dnd-html5-backend": "^14.1.0", - "react-doc-viewer": "git+https://git@github.com/warpdesign/react-doc-viewer.git#release", + "react-doc-viewer": "github:warpdesign/react-doc-viewer#release", "react-dom": "^16.9.0", "react-i18next": "^12.0.0", "react-virtual": "^2.10.4" diff --git a/src/components/dialogs/PreviewDialog.tsx b/src/components/dialogs/PreviewDialog.tsx index 7788b48..a9fd46e 100644 --- a/src/components/dialogs/PreviewDialog.tsx +++ b/src/components/dialogs/PreviewDialog.tsx @@ -2,7 +2,7 @@ import React, { KeyboardEvent as KE, ReactNode, useCallback, useEffect, useMemo, import { useStores } from '$src/hooks/useStores' import { Button, Classes, Colors, Dialog, Icon } from '@blueprintjs/core' import { observer } from 'mobx-react' -import DocViewer, { DocViewerRenderers } from 'react-doc-viewer' +import DocViewer, { DocViewerRenderers, IConfig } from 'react-doc-viewer' import { TypeIcons } from '$src/constants/icons' import { formatBytes } from '$src/utils/formatBytes' import { FileDescriptor } from '$src/services/Fs' @@ -93,6 +93,20 @@ export const PreviewDialog = observer(() => { ) } + // pre-calculate config to prevent unncessary re-rendering of the preview + const viewerConfig: IConfig = useMemo( + () => ({ + header: { + disableHeader: true, + }, + noRenderer: { + overrideComponent: NoPreviewRenderer, + }, + txtCodeTheme: settingsState.isDarkModeActive ? 'nord' : 'xcode', + }), + [], + ) + return ( cache.cursor && ( { style={{ maxHeight: '80vh', }} - config={{ - header: { - disableHeader: true, - }, - noRenderer: { - overrideComponent: NoPreviewRenderer, - }, - txtCodeTheme: settingsState.isDarkModeActive ? 'nord' : 'xcode', - }} + config={viewerConfig} documents={docs} initialActiveDocument={activeDocument} activeDocument={activeDocument}