Merge pull request #33162 from overleaf/cd-upload-generated-files-to-filetree

Cd upload generated files to filetree

GitOrigin-RevId: 2d2774e57c42452fba3a2582fde7153ffcde59bf
This commit is contained in:
Chris Dryden
2026-05-06 09:59:22 +01:00
committed by Copybot
parent 8f0979d6a2
commit df01c7e9e1
9 changed files with 745 additions and 41 deletions
@@ -12,6 +12,11 @@ import getMeta from '@/utils/meta'
import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
import { useProjectContext } from '@/shared/context/project-context'
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
import {
uploadBatch,
BatchUploadItem,
} from '@/infrastructure/batch-file-uploader'
import {
PythonRunner,
ExecutionContext,
@@ -41,14 +46,22 @@ export const PythonExecutionProvider: FC<PropsWithChildren> = ({
children,
}) => {
const { openDocs } = useEditorManagerContext()
const { projectSnapshot } = useProjectContext()
const { projectId, projectSnapshot } = useProjectContext()
const { pathInFolder } = useFileTreePathContext()
const { fileTreeData } = useFileTreeData()
const runnersRef = useRef(new Map<string, PythonRunner>())
const baseAssetPathRef = useRef<string | null>(null)
const pathInFolderRef = useRef(pathInFolder)
pathInFolderRef.current = pathInFolder
// Ref so the upload closure built into each PythonRunner reads the
// current value at call time rather than capturing a potentially-stale
// value from when the runner was constructed (fileTreeData may load
// after the runner is created).
const fileTreeDataRef = useRef(fileTreeData)
fileTreeDataRef.current = fileTreeData
// Refreshes the project snapshot and resolves the source code and all project
// files for the given fileId, to be passed to the executor for running.
const getExecutionContext = useCallback(
@@ -95,17 +108,31 @@ export const PythonExecutionProvider: FC<PropsWithChildren> = ({
).toString()
}
const uploadOutputFiles = (items: BatchUploadItem[]) => {
const folderId = fileTreeDataRef.current?._id
if (!folderId) {
return Promise.reject(
new Error('File tree not loaded; cannot upload output files')
)
}
return uploadBatch(items, {
projectId,
folderId,
})
}
const runner = new PythonRunner(
fileId,
baseAssetPathRef.current,
() => getExecutionContext(fileId),
createPyodideWorker
createPyodideWorker,
uploadOutputFiles
)
runner.init()
runnersRef.current.set(fileId, runner)
return runner
},
[getExecutionContext]
[getExecutionContext, projectId]
)
useEffect(() => {