pdf-preview-error.tsx 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. import { useTranslation, Trans } from 'react-i18next'
  2. import { memo, useCallback } from 'react'
  3. import OLButton from '@/features/ui/components/ol/ol-button'
  4. import PdfLogEntry from './pdf-log-entry'
  5. import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
  6. import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
  7. import getMeta from '../../../utils/meta'
  8. function PdfPreviewError({ error }: { error: string }) {
  9. const { t } = useTranslation()
  10. const { startCompile } = useCompileContext()
  11. switch (error) {
  12. case 'rendering-error-expected':
  13. return (
  14. <PdfLogEntry
  15. headerTitle={t('pdf_rendering_error')}
  16. formattedContent={
  17. <>
  18. <Trans
  19. i18nKey="something_went_wrong_rendering_pdf_expected"
  20. components={[
  21. // eslint-disable-next-line react/jsx-key
  22. <OLButton
  23. variant="info"
  24. size="sm"
  25. onClick={() => startCompile()}
  26. />,
  27. ]}
  28. />
  29. <br />
  30. <br />
  31. <Trans
  32. i18nKey="last_resort_trouble_shooting_guide"
  33. components={[
  34. // eslint-disable-next-line jsx-a11y/anchor-has-content
  35. <a
  36. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  37. target="_blank"
  38. key="troubleshooting-link"
  39. />,
  40. ]}
  41. />
  42. </>
  43. }
  44. level="warning"
  45. />
  46. )
  47. case 'rendering-error':
  48. return (
  49. <ErrorLogEntry title={t('pdf_rendering_error')}>
  50. {t('something_went_wrong_rendering_pdf')}
  51. &nbsp;
  52. <Trans
  53. i18nKey="try_recompile_project_or_troubleshoot"
  54. components={[
  55. // eslint-disable-next-line jsx-a11y/anchor-has-content
  56. <a
  57. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  58. target="_blank"
  59. key="troubleshooting-link"
  60. />,
  61. ]}
  62. />
  63. {getMeta('ol-compilesUserContentDomain') && (
  64. <>
  65. <br />
  66. <br />
  67. <Trans
  68. i18nKey="new_compile_domain_notice"
  69. values={{
  70. compilesUserContentDomain: new URL(
  71. getMeta('ol-compilesUserContentDomain')
  72. ).hostname,
  73. }}
  74. shouldUnescape
  75. tOptions={{ interpolation: { escapeValue: true } }}
  76. components={[
  77. <code key="domain" />,
  78. /* eslint-disable-next-line jsx-a11y/anchor-has-content */
  79. <a
  80. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  81. target="_blank"
  82. key="troubleshooting-link"
  83. />,
  84. ]}
  85. />
  86. </>
  87. )}
  88. </ErrorLogEntry>
  89. )
  90. case 'clsi-maintenance':
  91. return (
  92. <ErrorLogEntry title={t('server_error')}>
  93. {t('clsi_maintenance')}
  94. </ErrorLogEntry>
  95. )
  96. case 'clsi-unavailable':
  97. return (
  98. <ErrorLogEntry title={t('server_error')}>
  99. {t('clsi_unavailable')}
  100. </ErrorLogEntry>
  101. )
  102. case 'too-recently-compiled':
  103. return (
  104. <ErrorLogEntry title={t('server_error')}>
  105. {t('too_recently_compiled')}
  106. </ErrorLogEntry>
  107. )
  108. case 'terminated':
  109. return (
  110. <ErrorLogEntry title={t('terminated')}>
  111. {t('compile_terminated_by_user')}
  112. </ErrorLogEntry>
  113. )
  114. case 'rate-limited':
  115. return (
  116. <ErrorLogEntry title={t('pdf_compile_rate_limit_hit')}>
  117. {t('project_flagged_too_many_compiles')}
  118. </ErrorLogEntry>
  119. )
  120. case 'compile-in-progress':
  121. return (
  122. <ErrorLogEntry title={t('pdf_compile_in_progress_error')}>
  123. {t('pdf_compile_try_again')}
  124. </ErrorLogEntry>
  125. )
  126. case 'autocompile-disabled':
  127. return (
  128. <ErrorLogEntry title={t('autocompile_disabled')}>
  129. {t('autocompile_disabled_reason')}
  130. </ErrorLogEntry>
  131. )
  132. case 'project-too-large':
  133. return (
  134. <ErrorLogEntry title={t('project_too_large')}>
  135. {t('project_too_much_editable_text')}
  136. </ErrorLogEntry>
  137. )
  138. case 'timedout':
  139. return <TimedOutLogEntry />
  140. case 'failure':
  141. return (
  142. <ErrorLogEntry title={t('no_pdf_error_title')}>
  143. {t('no_pdf_error_explanation')}
  144. <ul className="my-1 ps-3">
  145. <li>{t('no_pdf_error_reason_unrecoverable_error')}</li>
  146. <li>
  147. <Trans
  148. i18nKey="no_pdf_error_reason_no_content"
  149. components={{ code: <code /> }}
  150. />
  151. </li>
  152. <li>
  153. <Trans
  154. i18nKey="no_pdf_error_reason_output_pdf_already_exists"
  155. components={{ code: <code /> }}
  156. />
  157. </li>
  158. </ul>
  159. </ErrorLogEntry>
  160. )
  161. case 'clear-cache':
  162. return (
  163. <ErrorLogEntry title={t('server_error')}>
  164. {t('somthing_went_wrong_compiling')}
  165. </ErrorLogEntry>
  166. )
  167. case 'pdf-viewer-loading-error':
  168. return (
  169. <ErrorLogEntry title={t('pdf_rendering_error')}>
  170. <Trans
  171. i18nKey="something_went_wrong_loading_pdf_viewer"
  172. components={[
  173. <strong key="strong-" />,
  174. // eslint-disable-next-line jsx-a11y/anchor-has-content
  175. <a
  176. href="/learn/how-to/Resolving_access%2C_loading%2C_and_display_problems"
  177. target="_blank"
  178. key="troubleshooting-link"
  179. />,
  180. // eslint-disable-next-line jsx-a11y/anchor-has-content
  181. <a key="contact-link" target="_blank" href="/contact" />,
  182. ]}
  183. />
  184. </ErrorLogEntry>
  185. )
  186. case 'validation-problems':
  187. return null // handled elsewhere
  188. case 'error':
  189. default:
  190. return (
  191. <ErrorLogEntry title={t('server_error')}>
  192. {t('somthing_went_wrong_compiling')}
  193. </ErrorLogEntry>
  194. )
  195. }
  196. }
  197. export default memo(PdfPreviewError)
  198. function ErrorLogEntry({
  199. title,
  200. headerIcon,
  201. children,
  202. }: {
  203. title: string
  204. headerIcon?: React.ReactElement
  205. children: React.ReactNode
  206. }) {
  207. const { t } = useTranslation()
  208. return (
  209. <PdfLogEntry
  210. headerTitle={title}
  211. headerIcon={headerIcon}
  212. formattedContent={children}
  213. entryAriaLabel={t('compile_error_entry_description')}
  214. level="error"
  215. />
  216. )
  217. }
  218. function TimedOutLogEntry() {
  219. const { t } = useTranslation()
  220. const { enableStopOnFirstError } = useStopOnFirstError({
  221. eventSource: 'timeout',
  222. })
  223. const { startCompile, lastCompileOptions, setAnimateCompileDropdownArrow } =
  224. useCompileContext()
  225. const handleEnableStopOnFirstErrorClick = useCallback(() => {
  226. enableStopOnFirstError()
  227. startCompile({ stopOnFirstError: true })
  228. setAnimateCompileDropdownArrow(true)
  229. }, [enableStopOnFirstError, startCompile, setAnimateCompileDropdownArrow])
  230. return (
  231. <ErrorLogEntry title={t('timedout')}>
  232. <p>{t('project_timed_out_intro')}</p>
  233. <ul>
  234. <li>
  235. <Trans
  236. i18nKey="project_timed_out_optimize_images"
  237. components={[
  238. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  239. <a href="https://www.overleaf.com/learn/how-to/Optimising_very_large_image_files" />,
  240. ]}
  241. />
  242. </li>
  243. <li>
  244. <Trans
  245. i18nKey="project_timed_out_fatal_error"
  246. components={[
  247. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  248. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F#Fatal_compile_errors_blocking_the_compilation" />,
  249. ]}
  250. />
  251. {!lastCompileOptions.stopOnFirstError && (
  252. <>
  253. {' '}
  254. <Trans
  255. i18nKey="project_timed_out_enable_stop_on_first_error"
  256. components={[
  257. // eslint-disable-next-line react/jsx-key
  258. <OLButton
  259. variant="info"
  260. size="sm"
  261. onClick={handleEnableStopOnFirstErrorClick}
  262. />,
  263. ]}
  264. />{' '}
  265. </>
  266. )}
  267. </li>
  268. </ul>
  269. <p>
  270. <Trans
  271. i18nKey="project_timed_out_learn_more"
  272. components={[
  273. // eslint-disable-next-line jsx-a11y/anchor-has-content, react/jsx-key
  274. <a href="https://www.overleaf.com/learn/how-to/Why_do_I_keep_getting_the_compile_timeout_error_message%3F" />,
  275. ]}
  276. />
  277. </p>
  278. </ErrorLogEntry>
  279. )
  280. }