local-compile-context.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. import {
  2. FC,
  3. createContext,
  4. useCallback,
  5. useContext,
  6. useEffect,
  7. useMemo,
  8. useRef,
  9. useState,
  10. } from 'react'
  11. import useScopeValue from '../hooks/use-scope-value'
  12. import useScopeValueSetterOnly from '../hooks/use-scope-value-setter-only'
  13. import usePersistedState from '../hooks/use-persisted-state'
  14. import useAbortController from '../hooks/use-abort-controller'
  15. import DocumentCompiler from '../../features/pdf-preview/util/compiler'
  16. import {
  17. send,
  18. sendMB,
  19. sendMBOnce,
  20. sendMBSampled,
  21. } from '../../infrastructure/event-tracking'
  22. import {
  23. buildLogEntryAnnotations,
  24. countRules,
  25. handleLogFiles,
  26. handleOutputFiles,
  27. } from '../../features/pdf-preview/util/output-files'
  28. import { useIdeContext } from './ide-context'
  29. import { useProjectContext } from './project-context'
  30. import { useEditorContext } from './editor-context'
  31. import { buildFileList } from '../../features/pdf-preview/util/file-list'
  32. import { useLayoutContext } from './layout-context'
  33. import { useUserContext } from './user-context'
  34. import { useFileTreeData } from '@/shared/context/file-tree-data-context'
  35. import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
  36. import { useUserSettingsContext } from '@/shared/context/user-settings-context'
  37. import { useSplitTestContext } from '@/shared/context/split-test-context'
  38. type PdfFile = Record<string, any>
  39. export type CompileContext = {
  40. autoCompile: boolean
  41. clearingCache: boolean
  42. clsiServerId?: string
  43. codeCheckFailed: boolean
  44. compiling: boolean
  45. deliveryLatencies: Record<string, any>
  46. draft: boolean
  47. error?: string
  48. fileList?: Record<string, any>
  49. hasChanges: boolean
  50. highlights?: Record<string, any>[]
  51. isProjectOwner: boolean
  52. logEntries?: Record<string, any>
  53. logEntryAnnotations?: Record<string, any>
  54. pdfDownloadUrl?: string
  55. pdfFile?: PdfFile
  56. pdfUrl?: string
  57. pdfViewer?: string
  58. position?: Record<string, any>
  59. rawLog?: string
  60. setAutoCompile: (value: boolean) => void
  61. setDraft: (value: any) => void
  62. setError: (value: any) => void
  63. setHasLintingError: (value: any) => void // only for storybook
  64. setHighlights: (value: any) => void
  65. setPosition: (value: any) => void
  66. setShowCompileTimeWarning: (value: any) => void
  67. setShowLogs: (value: boolean) => void
  68. toggleLogs: () => void
  69. setStopOnFirstError: (value: boolean) => void
  70. setStopOnValidationError: (value: boolean) => void
  71. showCompileTimeWarning: boolean
  72. showLogs: boolean
  73. showNewCompileTimeoutUI?: string
  74. showFasterCompilesFeedbackUI: boolean
  75. stopOnFirstError: boolean
  76. stopOnValidationError: boolean
  77. stoppedOnFirstError: boolean
  78. uncompiled?: boolean
  79. validationIssues?: Record<string, any>
  80. firstRenderDone: () => void
  81. cleanupCompileResult?: () => void
  82. animateCompileDropdownArrow: boolean
  83. editedSinceCompileStarted: boolean
  84. lastCompileOptions: any
  85. setAnimateCompileDropdownArrow: (value: boolean) => void
  86. recompileFromScratch: () => void
  87. setCompiling: (value: boolean) => void
  88. startCompile: (options?: any) => void
  89. stopCompile: () => void
  90. setChangedAt: (value: any) => void
  91. setSavedAt: (value: any) => void
  92. clearCache: () => void
  93. syncToEntry: (value: any) => void
  94. }
  95. export const LocalCompileContext = createContext<CompileContext | undefined>(
  96. undefined
  97. )
  98. export const LocalCompileProvider: FC = ({ children }) => {
  99. const ide = useIdeContext()
  100. const { hasPremiumCompile, isProjectOwner } = useEditorContext()
  101. const {
  102. _id: projectId,
  103. rootDocId,
  104. showNewCompileTimeoutUI,
  105. } = useProjectContext()
  106. const { pdfPreviewOpen } = useLayoutContext()
  107. const { features } = useUserContext()
  108. const { fileTreeData } = useFileTreeData()
  109. const { findEntityByPath } = useFileTreePathContext()
  110. // whether a compile is in progress
  111. const [compiling, setCompiling] = useState(false)
  112. // whether to show the compile time warning
  113. const [showCompileTimeWarning, setShowCompileTimeWarning] = useState(false)
  114. // the log entries parsed from the compile output log
  115. const [logEntries, setLogEntries] = useScopeValueSetterOnly('pdf.logEntries')
  116. // annotations for display in the editor, built from the log entries
  117. const [logEntryAnnotations, setLogEntryAnnotations] = useScopeValue(
  118. 'pdf.logEntryAnnotations'
  119. )
  120. // the PDF viewer and whether syntax validation is enabled globally
  121. const { userSettings } = useUserSettingsContext()
  122. const { pdfViewer, syntaxValidation } = userSettings
  123. // the URL for downloading the PDF
  124. const [, setPdfDownloadUrl] =
  125. useScopeValueSetterOnly<string>('pdf.downloadUrl')
  126. // the URL for loading the PDF in the preview pane
  127. const [, setPdfUrl] = useScopeValueSetterOnly<string>('pdf.url')
  128. // low level details for metrics
  129. const [pdfFile, setPdfFile] = useState<PdfFile | undefined>()
  130. useEffect(() => {
  131. setPdfDownloadUrl(pdfFile?.pdfDownloadUrl)
  132. setPdfUrl(pdfFile?.pdfUrl)
  133. }, [pdfFile, setPdfDownloadUrl, setPdfUrl])
  134. // the project is considered to be "uncompiled" if a doc has changed, or finished saving, since the last compile started.
  135. const [uncompiled, setUncompiled] = useScopeValue('pdf.uncompiled')
  136. // whether a doc has been edited since the last compile started
  137. const [editedSinceCompileStarted, setEditedSinceCompileStarted] =
  138. useState(false)
  139. // the id of the CLSI server which ran the compile
  140. const [clsiServerId, setClsiServerId] = useState()
  141. // data received in response to a compile request
  142. const [data, setData] = useState<Record<string, any>>()
  143. // the rootDocId used in the most recent compile request, which may not be the
  144. // same as the project rootDocId. This is used to calculate correct paths when
  145. // parsing the compile logs
  146. const lastCompileRootDocId = data?.rootDocId
  147. // callback to be invoked for PdfJsMetrics
  148. const [firstRenderDone, setFirstRenderDone] = useState(() => () => {})
  149. // latencies of compile/pdf download/rendering
  150. const [deliveryLatencies, setDeliveryLatencies] = useState({})
  151. // whether the project has been compiled yet
  152. const [compiledOnce, setCompiledOnce] = useState(false)
  153. // whether the cache is being cleared
  154. const [clearingCache, setClearingCache] = useState(false)
  155. // whether the logs should be visible
  156. const [showLogs, setShowLogs] = useState(false)
  157. // whether the faster compiles feedback UI should be displayed
  158. const [showFasterCompilesFeedbackUI, setShowFasterCompilesFeedbackUI] =
  159. useState(false)
  160. // whether the compile dropdown arrow should be animated
  161. const [animateCompileDropdownArrow, setAnimateCompileDropdownArrow] =
  162. useState(false)
  163. const toggleLogs = useCallback(() => {
  164. setShowLogs(prev => {
  165. if (!prev) {
  166. sendMBOnce('ide-open-logs-once')
  167. }
  168. return !prev
  169. })
  170. }, [setShowLogs])
  171. // an error that occurred
  172. const [error, setError] = useState<string>()
  173. // the list of files that can be downloaded
  174. const [fileList, setFileList] = useState<Record<string, any[]>>()
  175. // the raw contents of the log file
  176. const [rawLog, setRawLog] = useState<string>()
  177. // validation issues from CLSI
  178. const [validationIssues, setValidationIssues] = useState()
  179. // areas to highlight on the PDF, from synctex
  180. const [highlights, setHighlights] = useState()
  181. // scroll position of the PDF
  182. const [position, setPosition] = usePersistedState(`pdf.position.${projectId}`)
  183. // whether autocompile is switched on
  184. const [autoCompile, setAutoCompile] = usePersistedState(
  185. `autocompile_enabled:${projectId}`,
  186. false,
  187. true
  188. )
  189. // whether the compile should run in draft mode
  190. const [draft, setDraft] = usePersistedState(`draft:${projectId}`, false, true)
  191. // whether compiling should stop on first error
  192. const [stopOnFirstError, setStopOnFirstError] = usePersistedState(
  193. `stop_on_first_error:${projectId}`,
  194. false,
  195. true
  196. )
  197. // whether the last compiles stopped on first error
  198. const [stoppedOnFirstError, setStoppedOnFirstError] = useState(false)
  199. // whether compiling should be prevented if there are linting errors
  200. const [stopOnValidationError, setStopOnValidationError] = usePersistedState(
  201. `stop_on_validation_error:${projectId}`,
  202. true,
  203. true
  204. )
  205. // the Document currently open in the editor
  206. const [currentDoc] = useScopeValue('editor.sharejs_doc')
  207. // whether the editor linter found errors
  208. const [hasLintingError, setHasLintingError] = useScopeValue('hasLintingError')
  209. // the timestamp that a doc was last changed
  210. const [changedAt, setChangedAt] = useState(0)
  211. // the timestamp that a doc was last saved
  212. const [savedAt, setSavedAt] = useState(0)
  213. const { signal } = useAbortController()
  214. const cleanupCompileResult = useCallback(() => {
  215. setPdfFile(undefined)
  216. setLogEntries(null)
  217. setLogEntryAnnotations({})
  218. }, [setPdfFile, setLogEntries, setLogEntryAnnotations])
  219. const compilingRef = useRef(false)
  220. useEffect(() => {
  221. compilingRef.current = compiling
  222. }, [compiling])
  223. const _buildLogEntryAnnotations = useCallback(
  224. entries =>
  225. buildLogEntryAnnotations(entries, fileTreeData, lastCompileRootDocId),
  226. [fileTreeData, lastCompileRootDocId]
  227. )
  228. const buildLogEntryAnnotationsRef = useRef(_buildLogEntryAnnotations)
  229. useEffect(() => {
  230. buildLogEntryAnnotationsRef.current = _buildLogEntryAnnotations
  231. }, [_buildLogEntryAnnotations])
  232. // the document compiler
  233. const [compiler] = useState(() => {
  234. return new DocumentCompiler({
  235. projectId,
  236. setChangedAt,
  237. setSavedAt,
  238. setCompiling,
  239. setData,
  240. setFirstRenderDone,
  241. setDeliveryLatencies,
  242. setError,
  243. cleanupCompileResult,
  244. compilingRef,
  245. signal,
  246. })
  247. })
  248. // keep currentDoc in sync with the compiler
  249. useEffect(() => {
  250. compiler.currentDoc = currentDoc
  251. }, [compiler, currentDoc])
  252. // keep the project rootDocId in sync with the compiler
  253. useEffect(() => {
  254. compiler.projectRootDocId = rootDocId
  255. }, [compiler, rootDocId])
  256. // keep draft setting in sync with the compiler
  257. useEffect(() => {
  258. compiler.setOption('draft', draft)
  259. }, [compiler, draft])
  260. // keep stop on first error setting in sync with the compiler
  261. useEffect(() => {
  262. compiler.setOption('stopOnFirstError', stopOnFirstError)
  263. }, [compiler, stopOnFirstError])
  264. useEffect(() => {
  265. setUncompiled(changedAt > 0 || savedAt > 0)
  266. }, [setUncompiled, changedAt, savedAt])
  267. useEffect(() => {
  268. setEditedSinceCompileStarted(changedAt > 0)
  269. }, [setEditedSinceCompileStarted, changedAt])
  270. // always compile the PDF once after opening the project, after the doc has loaded
  271. useEffect(() => {
  272. if (!compiledOnce && currentDoc) {
  273. setCompiledOnce(true)
  274. compiler.compile({ isAutoCompileOnLoad: true })
  275. }
  276. }, [compiledOnce, currentDoc, compiler])
  277. useEffect(() => {
  278. const compileTimeWarningEnabled =
  279. features?.compileTimeout !== undefined && features.compileTimeout <= 60
  280. if (compileTimeWarningEnabled && compiling && isProjectOwner) {
  281. const timeout = window.setTimeout(() => {
  282. setShowCompileTimeWarning(true)
  283. }, 30000)
  284. return () => {
  285. window.clearTimeout(timeout)
  286. }
  287. }
  288. }, [compiling, isProjectOwner, features])
  289. const { splitTestVariants } = useSplitTestContext()
  290. // handle the data returned from a compile request
  291. // note: this should _only_ run when `data` changes,
  292. // the other dependencies must all be static
  293. useEffect(() => {
  294. const abortController = new AbortController()
  295. if (data) {
  296. if (data.clsiServerId) {
  297. setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
  298. }
  299. setShowFasterCompilesFeedbackUI(
  300. Boolean(data.showFasterCompilesFeedbackUI)
  301. )
  302. if (data.outputFiles) {
  303. const outputFiles = new Map()
  304. for (const outputFile of data.outputFiles) {
  305. outputFiles.set(outputFile.path, outputFile)
  306. }
  307. // set the PDF context
  308. if (data.status === 'success') {
  309. setPdfFile(handleOutputFiles(outputFiles, projectId, data))
  310. }
  311. setFileList(
  312. buildFileList(outputFiles, data.clsiServerId, data.compileGroup)
  313. )
  314. // handle log files
  315. // asynchronous (TODO: cancel on new compile?)
  316. setLogEntryAnnotations(null)
  317. setLogEntries(null)
  318. setRawLog(undefined)
  319. handleLogFiles(outputFiles, data, abortController.signal).then(
  320. (result: Record<string, any>) => {
  321. setRawLog(result.log)
  322. setLogEntries(result.logEntries)
  323. setLogEntryAnnotations(
  324. buildLogEntryAnnotationsRef.current(result.logEntries.all)
  325. )
  326. // sample compile stats for real users
  327. if (!window.user.alphaProgram) {
  328. if (['success', 'stopped-on-first-error'].includes(data.status)) {
  329. sendMBSampled(
  330. 'compile-result',
  331. {
  332. errors: result.logEntries.errors.length,
  333. warnings: result.logEntries.warnings.length,
  334. typesetting: result.logEntries.typesetting.length,
  335. newPdfPreview: true, // TODO: is this useful?
  336. stopOnFirstError: data.options.stopOnFirstError,
  337. },
  338. 0.01
  339. )
  340. }
  341. if (splitTestVariants['compile-log-events'] === 'enabled') {
  342. sendMB('compile-log-entries', {
  343. status: data.status,
  344. stopOnFirstError: data.options.stopOnFirstError,
  345. isAutoCompileOnLoad: !!data.options.isAutoCompileOnLoad,
  346. isAutoCompileOnChange: !!data.options.isAutoCompileOnChange,
  347. errors: countRules(result.logEntries.errors),
  348. warnings: countRules(result.logEntries.warnings),
  349. typesetting: countRules(result.logEntries.typesetting),
  350. })
  351. }
  352. }
  353. }
  354. )
  355. }
  356. switch (data.status) {
  357. case 'success':
  358. setError(undefined)
  359. setShowLogs(false)
  360. break
  361. case 'stopped-on-first-error':
  362. setError(undefined)
  363. setShowLogs(true)
  364. break
  365. case 'clsi-maintenance':
  366. case 'compile-in-progress':
  367. case 'exited':
  368. case 'failure':
  369. case 'project-too-large':
  370. case 'rate-limited':
  371. case 'terminated':
  372. case 'too-recently-compiled':
  373. setError(data.status)
  374. break
  375. case 'timedout':
  376. setError('timedout')
  377. if (!hasPremiumCompile && isProjectOwner) {
  378. send(
  379. 'subscription-funnel',
  380. 'editor-click-feature',
  381. 'compile-timeout'
  382. )
  383. }
  384. break
  385. case 'autocompile-backoff':
  386. if (!data.options.isAutoCompileOnLoad) {
  387. setError('autocompile-disabled')
  388. setAutoCompile(false)
  389. }
  390. break
  391. case 'unavailable':
  392. setError('clsi-unavailable')
  393. break
  394. case 'validation-problems':
  395. setError('validation-problems')
  396. setValidationIssues(data.validationProblems)
  397. break
  398. default:
  399. setError('error')
  400. break
  401. }
  402. setStoppedOnFirstError(data.status === 'stopped-on-first-error')
  403. }
  404. return () => {
  405. abortController.abort()
  406. }
  407. }, [
  408. data,
  409. ide,
  410. hasPremiumCompile,
  411. isProjectOwner,
  412. projectId,
  413. setAutoCompile,
  414. setClsiServerId,
  415. setLogEntries,
  416. setLogEntryAnnotations,
  417. setPdfFile,
  418. splitTestVariants,
  419. ])
  420. // switch to logs if there's an error
  421. useEffect(() => {
  422. if (error) {
  423. setShowLogs(true)
  424. }
  425. }, [error])
  426. // whether there has been an autocompile linting error, if syntax validation is switched on
  427. const autoCompileLintingError = Boolean(
  428. autoCompile && syntaxValidation && hasLintingError
  429. )
  430. const codeCheckFailed = stopOnValidationError && autoCompileLintingError
  431. // the project is available for auto-compiling
  432. // (autocompile is enabled, the PDF preview is open, and the code check (if enabled) hasn't failed)
  433. const canAutoCompile = Boolean(
  434. autoCompile && pdfPreviewOpen && !codeCheckFailed
  435. )
  436. // show that the project has pending changes
  437. const hasChanges = Boolean(canAutoCompile && uncompiled && compiledOnce)
  438. // call the debounced autocompile function if the project is available for auto-compiling and it has changed
  439. useEffect(() => {
  440. if (canAutoCompile) {
  441. if (changedAt > 0 || savedAt > 0) {
  442. compiler.debouncedAutoCompile()
  443. }
  444. } else {
  445. compiler.debouncedAutoCompile.cancel()
  446. }
  447. }, [compiler, canAutoCompile, changedAt, savedAt])
  448. // cancel debounced recompile on unmount
  449. useEffect(() => {
  450. return () => {
  451. compiler.debouncedAutoCompile.cancel()
  452. }
  453. }, [compiler])
  454. // start a compile manually
  455. const startCompile = useCallback(
  456. options => {
  457. compiler.compile(options)
  458. },
  459. [compiler]
  460. )
  461. // stop a compile manually
  462. const stopCompile = useCallback(() => {
  463. compiler.stopCompile()
  464. }, [compiler])
  465. // clear the compile cache
  466. const clearCache = useCallback(() => {
  467. setClearingCache(true)
  468. return compiler
  469. .clearCache()
  470. .then(() => {
  471. setFileList(undefined)
  472. setPdfFile(undefined)
  473. })
  474. .finally(() => {
  475. setClearingCache(false)
  476. })
  477. }, [compiler])
  478. const syncToEntry = useCallback(
  479. entry => {
  480. const result = findEntityByPath(entry.file)
  481. if (result && result.type === 'doc') {
  482. ide.editorManager.openDocId(result.entity._id, {
  483. gotoLine: entry.line ?? undefined,
  484. gotoColumn: entry.column ?? undefined,
  485. })
  486. }
  487. },
  488. [findEntityByPath, ide.editorManager]
  489. )
  490. // clear the cache then run a compile, triggered by a menu item
  491. const recompileFromScratch = useCallback(() => {
  492. clearCache().then(() => {
  493. compiler.compile()
  494. })
  495. }, [clearCache, compiler])
  496. // After a compile, the compiler sets `data.options` to the options that were
  497. // used for that compile.
  498. const lastCompileOptions = useMemo(() => data?.options || {}, [data])
  499. const value = useMemo(
  500. () => ({
  501. animateCompileDropdownArrow,
  502. autoCompile,
  503. clearCache,
  504. clearingCache,
  505. clsiServerId,
  506. codeCheckFailed,
  507. compiling,
  508. deliveryLatencies,
  509. draft,
  510. editedSinceCompileStarted,
  511. error,
  512. fileList,
  513. hasChanges,
  514. highlights,
  515. isProjectOwner,
  516. lastCompileOptions,
  517. logEntryAnnotations,
  518. logEntries,
  519. pdfDownloadUrl: pdfFile?.pdfDownloadUrl,
  520. pdfFile,
  521. pdfUrl: pdfFile?.pdfUrl,
  522. pdfViewer,
  523. position,
  524. rawLog,
  525. recompileFromScratch,
  526. setAnimateCompileDropdownArrow,
  527. setAutoCompile,
  528. setCompiling,
  529. setDraft,
  530. setError,
  531. setHasLintingError, // only for stories
  532. setHighlights,
  533. setPosition,
  534. showCompileTimeWarning,
  535. setShowCompileTimeWarning,
  536. setShowLogs,
  537. toggleLogs,
  538. setStopOnFirstError,
  539. setStopOnValidationError,
  540. showLogs,
  541. showNewCompileTimeoutUI,
  542. showFasterCompilesFeedbackUI,
  543. startCompile,
  544. stopCompile,
  545. stopOnFirstError,
  546. stopOnValidationError,
  547. stoppedOnFirstError,
  548. uncompiled,
  549. validationIssues,
  550. firstRenderDone,
  551. setChangedAt,
  552. setSavedAt,
  553. cleanupCompileResult,
  554. syncToEntry,
  555. }),
  556. [
  557. animateCompileDropdownArrow,
  558. autoCompile,
  559. clearCache,
  560. clearingCache,
  561. clsiServerId,
  562. codeCheckFailed,
  563. compiling,
  564. deliveryLatencies,
  565. draft,
  566. editedSinceCompileStarted,
  567. error,
  568. fileList,
  569. hasChanges,
  570. highlights,
  571. isProjectOwner,
  572. lastCompileOptions,
  573. logEntries,
  574. logEntryAnnotations,
  575. position,
  576. pdfFile,
  577. pdfViewer,
  578. rawLog,
  579. recompileFromScratch,
  580. setAnimateCompileDropdownArrow,
  581. setAutoCompile,
  582. setDraft,
  583. setError,
  584. setHasLintingError, // only for stories
  585. setHighlights,
  586. setPosition,
  587. setShowCompileTimeWarning,
  588. setStopOnFirstError,
  589. setStopOnValidationError,
  590. showCompileTimeWarning,
  591. showLogs,
  592. showNewCompileTimeoutUI,
  593. showFasterCompilesFeedbackUI,
  594. startCompile,
  595. stopCompile,
  596. stopOnFirstError,
  597. stopOnValidationError,
  598. stoppedOnFirstError,
  599. uncompiled,
  600. validationIssues,
  601. firstRenderDone,
  602. setChangedAt,
  603. setSavedAt,
  604. cleanupCompileResult,
  605. setShowLogs,
  606. toggleLogs,
  607. syncToEntry,
  608. ]
  609. )
  610. return (
  611. <LocalCompileContext.Provider value={value}>
  612. {children}
  613. </LocalCompileContext.Provider>
  614. )
  615. }
  616. export function useLocalCompileContext() {
  617. const context = useContext(LocalCompileContext)
  618. if (!context) {
  619. throw new Error(
  620. 'useLocalCompileContext is only available inside LocalCompileProvider'
  621. )
  622. }
  623. return context
  624. }