From fa0ea24f5349a9714bf2b8ce1b6ded08d6071810 Mon Sep 17 00:00:00 2001 From: Tim Down <158919+timdown@users.noreply.github.com> Date: Tue, 21 Nov 2023 14:12:41 +0000 Subject: [PATCH] Merge pull request #15804 from overleaf/td-compile-log-links Fix bug with compile log links GitOrigin-RevId: fc10b6dcd09ba36fb358fbd1a13012205d4f568d --- .../js/features/pdf-preview/util/compiler.js | 10 ++++++---- .../js/shared/context/local-compile-context.jsx | 16 +++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/services/web/frontend/js/features/pdf-preview/util/compiler.js b/services/web/frontend/js/features/pdf-preview/util/compiler.js index 9d43bc23c5..2887b9234b 100644 --- a/services/web/frontend/js/features/pdf-preview/util/compiler.js +++ b/services/web/frontend/js/features/pdf-preview/util/compiler.js @@ -19,7 +19,6 @@ export default class DocumentCompiler { constructor({ compilingRef, projectId, - rootDocId, setChangedAt, setSavedAt, setCompiling, @@ -32,7 +31,6 @@ export default class DocumentCompiler { }) { this.compilingRef = compilingRef this.projectId = projectId - this.rootDocId = rootDocId this.setChangedAt = setChangedAt this.setSavedAt = setSavedAt this.setCompiling = setCompiling @@ -43,6 +41,7 @@ export default class DocumentCompiler { this.cleanupCompileResult = cleanupCompileResult this.signal = signal + this.projectRootDocId = null this.clsiServerId = null this.currentDoc = null this.error = undefined @@ -95,8 +94,10 @@ export default class DocumentCompiler { const t0 = performance.now() + const rootDocId = this.getRootDocOverrideId() + const body = { - rootDoc_id: this.getRootDocOverrideId(), + rootDoc_id: rootDocId, draft: options.draft, check: 'silent', // NOTE: 'error' and 'validate' are possible, but unused // use incremental compile for all users but revert to a full compile @@ -123,6 +124,7 @@ export default class DocumentCompiler { this.setError(undefined) data.options = options + data.rootDocId = rootDocId if (data.clsiServerId) { this.clsiServerId = data.clsiServerId } @@ -140,7 +142,7 @@ export default class DocumentCompiler { // if it contains "\documentclass" then use this as the root doc getRootDocOverrideId() { // only override when not in the root doc itself - if (this.currentDoc.doc_id !== this.rootDocId) { + if (this.currentDoc.doc_id !== this.projectRootDocId) { const snapshot = this.currentDoc.getSnapshot() if (snapshot && isMainFile(snapshot)) { diff --git a/services/web/frontend/js/shared/context/local-compile-context.jsx b/services/web/frontend/js/shared/context/local-compile-context.jsx index b01a317d2c..7f55aed245 100644 --- a/services/web/frontend/js/shared/context/local-compile-context.jsx +++ b/services/web/frontend/js/shared/context/local-compile-context.jsx @@ -144,6 +144,11 @@ export function LocalCompileProvider({ children }) { // data received in response to a compile request const [data, setData] = useState() + // the rootDocId used in the most recent compile request, which may not be the + // same as the project rootDocId. This is used to calculate correct paths when + // parsing the compile logs + const lastCompileRootDocId = data?.rootDocId + // callback to be invoked for PdfJsMetrics const [firstRenderDone, setFirstRenderDone] = useState(() => () => {}) @@ -251,8 +256,9 @@ export function LocalCompileProvider({ children }) { }, [compiling]) const _buildLogEntryAnnotations = useCallback( - entries => buildLogEntryAnnotations(entries, fileTreeData, rootDocId), - [fileTreeData, rootDocId] + entries => + buildLogEntryAnnotations(entries, fileTreeData, lastCompileRootDocId), + [fileTreeData, lastCompileRootDocId] ) const buildLogEntryAnnotationsRef = useRef(_buildLogEntryAnnotations) @@ -265,7 +271,6 @@ export function LocalCompileProvider({ children }) { const [compiler] = useState(() => { return new DocumentCompiler({ projectId, - rootDocId, setChangedAt, setSavedAt, setCompiling, @@ -284,6 +289,11 @@ export function LocalCompileProvider({ children }) { compiler.currentDoc = currentDoc }, [compiler, currentDoc]) + // keep the project rootDocId in sync with the compiler + useEffect(() => { + compiler.projectRootDocId = rootDocId + }, [compiler, rootDocId]) + // keep draft setting in sync with the compiler useEffect(() => { compiler.setOption('draft', draft)