From 94c8fe5b93df048c46a99d21d22be47921076134 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Thu, 31 Jul 2025 14:04:36 +0100 Subject: [PATCH] Display an error message when the synctex request fails (#27523) GitOrigin-RevId: 4a57058386ba8b11dee90ef13e374411db54e2cc --- .../web/frontend/extracted-translations.json | 1 + .../pdf-preview/components/synctex-toasts.tsx | 26 +++++++++++++++++++ .../features/pdf-preview/hooks/use-synctex.ts | 15 ++++++++--- services/web/locales/en.json | 1 + 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/services/web/frontend/extracted-translations.json b/services/web/frontend/extracted-translations.json index 28d0a1edb0..7bab4594dd 100644 --- a/services/web/frontend/extracted-translations.json +++ b/services/web/frontend/extracted-translations.json @@ -1747,6 +1747,7 @@ "sync_project_to_github_explanation": "", "sync_to_dropbox": "", "sync_to_github": "", + "synctex_error_recompile_and_try_again": "", "synctex_failed": "", "syntax_validation": "", "tab_connecting": "", diff --git a/services/web/frontend/js/features/pdf-preview/components/synctex-toasts.tsx b/services/web/frontend/js/features/pdf-preview/components/synctex-toasts.tsx index 62806b85e9..5f62a64737 100644 --- a/services/web/frontend/js/features/pdf-preview/components/synctex-toasts.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/synctex-toasts.tsx @@ -21,6 +21,12 @@ export const SynctexFileErrorToast = () => { ) } +export const SynctexRequestErrorToast = () => { + const { t } = useTranslation() + + return {t('synctex_error_recompile_and_try_again')} +} + const generators: GlobalToastGeneratorEntry[] = [ { key: 'synctex:file-error', @@ -32,6 +38,16 @@ const generators: GlobalToastGeneratorEntry[] = [ isDismissible: true, }), }, + { + key: 'synctex:request-error', + generator: () => ({ + content: , + type: 'warning', + autoHide: true, + delay: 4000, + isDismissible: true, + }), + }, ] export default generators @@ -45,3 +61,13 @@ export const showFileErrorToast = () => { }) ) } + +export const showSynctexRequestErrorToast = () => { + window.dispatchEvent( + new CustomEvent('ide:show-toast', { + detail: { + key: 'synctex:request-error', + }, + }) + ) +} diff --git a/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts b/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts index 0a0a9f64f6..e6c24c4105 100644 --- a/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts +++ b/services/web/frontend/js/features/pdf-preview/hooks/use-synctex.ts @@ -17,7 +17,10 @@ import useEventListener from '@/shared/hooks/use-event-listener' import { CursorPosition } from '@/features/ide-react/types/cursor-position' import { isValidTeXFile } from '@/main/is-valid-tex-file' import { PdfScrollPosition } from '@/shared/hooks/use-pdf-scroll-position' -import { showFileErrorToast } from '@/features/pdf-preview/components/synctex-toasts' +import { + showFileErrorToast, + showSynctexRequestErrorToast, +} from '@/features/pdf-preview/components/synctex-toasts' import { sendMB } from '@/infrastructure/event-tracking' export default function useSynctex(): { @@ -125,7 +128,10 @@ export default function useSynctex(): { }) } }) - .catch(debugConsole.error) + .catch(error => { + showSynctexRequestErrorToast() + debugConsole.error(error) + }) .finally(() => { if (isMounted.current) { setSyncToPdfInFlight(false) @@ -236,7 +242,10 @@ export default function useSynctex(): { }) } }) - .catch(debugConsole.error) + .catch(error => { + debugConsole.error(error) + showSynctexRequestErrorToast() + }) .finally(() => { if (isMounted.current) { setSyncToCodeInFlight(false) diff --git a/services/web/locales/en.json b/services/web/locales/en.json index 6a4c84568a..b6cd1f4d48 100644 --- a/services/web/locales/en.json +++ b/services/web/locales/en.json @@ -2246,6 +2246,7 @@ "sync_project_to_github_explanation": "Any changes you have made in __appName__ will be committed and merged with any updates in GitHub.", "sync_to_dropbox": "Sync to Dropbox", "sync_to_github": "Sync to GitHub", + "synctex_error_recompile_and_try_again": "That didn’t work. Recompile and try again.", "synctex_failed": "Couldn’t find the corresponding source file", "syntax_validation": "Code check", "tab_connecting": "Connecting with the editor",