mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-11 08:16:28 +00:00
Merge pull request #8841 from overleaf/jpa-fix-detach-state-propagation
[web] fix de-sync of pdfFile vs pdfUrl vs pdfDownloadUrl GitOrigin-RevId: 1c30f372580b7d247d005c4e4cd623996449c212
This commit is contained in:
parent
6a6b6a0c88
commit
9d9630e972
3 changed files with 40 additions and 62 deletions
|
@ -7,35 +7,34 @@ import { v4 as uuid } from 'uuid'
|
|||
const TRANSIENT_WARNING_REGEX = /^(Reference|Citation).+undefined on input line/
|
||||
|
||||
export function handleOutputFiles(outputFiles, projectId, data) {
|
||||
const result = {}
|
||||
|
||||
const outputFile = outputFiles.get('output.pdf')
|
||||
result.pdfFile = outputFile
|
||||
if (!outputFile) return null
|
||||
|
||||
if (outputFile) {
|
||||
// build the URL for viewing the PDF in the preview UI
|
||||
const params = new URLSearchParams({
|
||||
compileGroup: data.compileGroup,
|
||||
})
|
||||
// build the URL for viewing the PDF in the preview UI
|
||||
const params = new URLSearchParams({
|
||||
compileGroup: data.compileGroup,
|
||||
})
|
||||
|
||||
if (data.clsiServerId) {
|
||||
params.set('clsiserverid', data.clsiServerId)
|
||||
}
|
||||
|
||||
if (getMeta('ol-pdfCachingMode') === 'enabled') {
|
||||
// Tag traffic that uses the pdf caching logic.
|
||||
params.set('enable_pdf_caching', 'true')
|
||||
}
|
||||
|
||||
result.pdfUrl = `${buildURL(outputFile, data.pdfDownloadDomain)}?${params}`
|
||||
|
||||
// build the URL for downloading the PDF
|
||||
params.set('popupDownload', 'true') // save PDF download as file
|
||||
|
||||
result.pdfDownloadUrl = `/download/project/${projectId}/build/${outputFile.build}/output/output.pdf?${params}`
|
||||
if (data.clsiServerId) {
|
||||
params.set('clsiserverid', data.clsiServerId)
|
||||
}
|
||||
|
||||
return result
|
||||
if (getMeta('ol-pdfCachingMode') === 'enabled') {
|
||||
// Tag traffic that uses the pdf caching logic.
|
||||
params.set('enable_pdf_caching', 'true')
|
||||
}
|
||||
|
||||
outputFile.pdfUrl = `${buildURL(
|
||||
outputFile,
|
||||
data.pdfDownloadDomain
|
||||
)}?${params}`
|
||||
|
||||
// build the URL for downloading the PDF
|
||||
params.set('popupDownload', 'true') // save PDF download as file
|
||||
|
||||
outputFile.pdfDownloadUrl = `/download/project/${projectId}/build/${outputFile.build}/output/output.pdf?${params}`
|
||||
|
||||
return outputFile
|
||||
}
|
||||
|
||||
export const handleLogFiles = async (outputFiles, data, signal) => {
|
||||
|
|
|
@ -35,9 +35,7 @@ export function DetachCompileProvider({ children }) {
|
|||
lastCompileOptions: _lastCompileOptions,
|
||||
logEntries: _logEntries,
|
||||
logEntryAnnotations: _logEntryAnnotations,
|
||||
pdfDownloadUrl: _pdfDownloadUrl,
|
||||
pdfFile: _pdfFile,
|
||||
pdfUrl: _pdfUrl,
|
||||
pdfViewer: _pdfViewer,
|
||||
position: _position,
|
||||
rawLog: _rawLog,
|
||||
|
@ -151,24 +149,12 @@ export function DetachCompileProvider({ children }) {
|
|||
'detacher',
|
||||
'detached'
|
||||
)
|
||||
const [pdfDownloadUrl] = useDetachStateWatcher(
|
||||
'pdfDownloadUrl',
|
||||
_pdfDownloadUrl,
|
||||
'detacher',
|
||||
'detached'
|
||||
)
|
||||
const [pdfFile] = useDetachStateWatcher(
|
||||
'pdfFile',
|
||||
_pdfFile,
|
||||
'detacher',
|
||||
'detached'
|
||||
)
|
||||
const [pdfUrl] = useDetachStateWatcher(
|
||||
'pdfUrl',
|
||||
_pdfUrl,
|
||||
'detacher',
|
||||
'detached'
|
||||
)
|
||||
const [pdfViewer] = useDetachStateWatcher(
|
||||
'pdfViewer',
|
||||
_pdfViewer,
|
||||
|
@ -375,9 +361,9 @@ export function DetachCompileProvider({ children }) {
|
|||
lastCompileOptions,
|
||||
logEntryAnnotations,
|
||||
logEntries,
|
||||
pdfDownloadUrl,
|
||||
pdfDownloadUrl: pdfFile?.pdfDownloadUrl,
|
||||
pdfFile,
|
||||
pdfUrl,
|
||||
pdfUrl: pdfFile?.pdfUrl,
|
||||
pdfViewer,
|
||||
position,
|
||||
rawLog,
|
||||
|
@ -426,9 +412,7 @@ export function DetachCompileProvider({ children }) {
|
|||
lastCompileOptions,
|
||||
logEntryAnnotations,
|
||||
logEntries,
|
||||
pdfDownloadUrl,
|
||||
pdfFile,
|
||||
pdfUrl,
|
||||
pdfViewer,
|
||||
position,
|
||||
rawLog,
|
||||
|
|
|
@ -105,15 +105,19 @@ export function LocalCompileProvider({ children }) {
|
|||
const [pdfViewer] = useScopeValue('settings.pdfViewer')
|
||||
|
||||
// the URL for downloading the PDF
|
||||
const [pdfDownloadUrl, setPdfDownloadUrl] =
|
||||
useScopeValueSetterOnly('pdf.downloadUrl')
|
||||
const [, setPdfDownloadUrl] = useScopeValueSetterOnly('pdf.downloadUrl')
|
||||
|
||||
// the URL for loading the PDF in the preview pane
|
||||
const [pdfUrl, setPdfUrl] = useScopeValueSetterOnly('pdf.url')
|
||||
const [, setPdfUrl] = useScopeValueSetterOnly('pdf.url')
|
||||
|
||||
// low level details for metrics
|
||||
const [pdfFile, setPdfFile] = useState()
|
||||
|
||||
useEffect(() => {
|
||||
setPdfDownloadUrl(pdfFile?.pdfDownloadUrl)
|
||||
setPdfUrl(pdfFile?.pdfUrl)
|
||||
}, [pdfFile, setPdfDownloadUrl, setPdfUrl])
|
||||
|
||||
// the project is considered to be "uncompiled" if a doc has changed since the last compile started
|
||||
const [uncompiled, setUncompiled] = useScopeValue('pdf.uncompiled')
|
||||
|
||||
|
@ -215,11 +219,10 @@ export function LocalCompileProvider({ children }) {
|
|||
const { signal } = useAbortController()
|
||||
|
||||
const cleanupCompileResult = useCallback(() => {
|
||||
setPdfUrl(null)
|
||||
setPdfDownloadUrl(null)
|
||||
setPdfFile(null)
|
||||
setLogEntries(null)
|
||||
setLogEntryAnnotations({})
|
||||
}, [setPdfUrl, setPdfDownloadUrl, setLogEntries, setLogEntryAnnotations])
|
||||
}, [setPdfFile, setLogEntries, setLogEntryAnnotations])
|
||||
|
||||
const compilingRef = useRef(false)
|
||||
|
||||
|
@ -308,12 +311,9 @@ export function LocalCompileProvider({ children }) {
|
|||
outputFiles.set(outputFile.path, outputFile)
|
||||
}
|
||||
|
||||
// set the PDF URLs
|
||||
const result = handleOutputFiles(outputFiles, projectId, data)
|
||||
// set the PDF context
|
||||
if (data.status === 'success') {
|
||||
setPdfDownloadUrl(result.pdfDownloadUrl)
|
||||
setPdfFile(result.pdfFile)
|
||||
setPdfUrl(result.pdfUrl)
|
||||
setPdfFile(handleOutputFiles(outputFiles, projectId, data))
|
||||
}
|
||||
|
||||
setFileList(
|
||||
|
@ -429,9 +429,7 @@ export function LocalCompileProvider({ children }) {
|
|||
setClsiServerId,
|
||||
setLogEntries,
|
||||
setLogEntryAnnotations,
|
||||
setPdfDownloadUrl,
|
||||
setPdfFile,
|
||||
setPdfUrl,
|
||||
])
|
||||
|
||||
// switch to logs if there's an error
|
||||
|
@ -493,13 +491,12 @@ export function LocalCompileProvider({ children }) {
|
|||
.clearCache()
|
||||
.then(() => {
|
||||
setFileList(undefined)
|
||||
setPdfDownloadUrl(undefined)
|
||||
setPdfUrl(undefined)
|
||||
setPdfFile(undefined)
|
||||
})
|
||||
.finally(() => {
|
||||
setClearingCache(false)
|
||||
})
|
||||
}, [compiler, setPdfDownloadUrl, setPdfUrl])
|
||||
}, [compiler])
|
||||
|
||||
// clear the cache then run a compile, triggered by a menu item
|
||||
const recompileFromScratch = useCallback(() => {
|
||||
|
@ -530,9 +527,9 @@ export function LocalCompileProvider({ children }) {
|
|||
lastCompileOptions,
|
||||
logEntryAnnotations,
|
||||
logEntries,
|
||||
pdfDownloadUrl,
|
||||
pdfDownloadUrl: pdfFile?.pdfDownloadUrl,
|
||||
pdfFile,
|
||||
pdfUrl,
|
||||
pdfUrl: pdfFile?.pdfUrl,
|
||||
pdfViewer,
|
||||
position,
|
||||
rawLog,
|
||||
|
@ -582,9 +579,7 @@ export function LocalCompileProvider({ children }) {
|
|||
logEntries,
|
||||
logEntryAnnotations,
|
||||
position,
|
||||
pdfDownloadUrl,
|
||||
pdfFile,
|
||||
pdfUrl,
|
||||
pdfViewer,
|
||||
rawLog,
|
||||
recompileFromScratch,
|
||||
|
|
Loading…
Add table
Reference in a new issue