From e7a97f94438ea00d4b3c42cac717ce863f576d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 11 Sep 2024 10:39:06 +0200 Subject: [PATCH] Debug turbo events in development --- frontend/src/turbo/constants.ts | 17 +++++++++++++++++ frontend/src/turbo/setup.ts | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 frontend/src/turbo/constants.ts diff --git a/frontend/src/turbo/constants.ts b/frontend/src/turbo/constants.ts new file mode 100644 index 000000000000..267b6882de0c --- /dev/null +++ b/frontend/src/turbo/constants.ts @@ -0,0 +1,17 @@ +export const TURBO_EVENTS:string[] = [ + 'turbo:click', + 'turbo:before-visit', + 'turbo:visit', + 'turbo:submit-start', + 'turbo:before-fetch-request', + 'turbo:before-fetch-response', + 'turbo:submit-end', + 'turbo:before-cache', + 'turbo:before-render', + 'turbo:before-stream-render', + 'turbo:render', + 'turbo:load', + 'turbo:frame-render', + 'turbo:frame-load', + 'turbo:fetch-request-error', +]; diff --git a/frontend/src/turbo/setup.ts b/frontend/src/turbo/setup.ts index 4c4f9f54bce1..f9db91d4dcf3 100644 --- a/frontend/src/turbo/setup.ts +++ b/frontend/src/turbo/setup.ts @@ -5,12 +5,23 @@ import { registerDialogStreamAction } from './dialog-stream-action'; import { addTurboEventListeners } from './turbo-event-listeners'; import { registerFlashStreamAction } from './flash-stream-action'; import { applyTurboNavigationPatch } from './turbo-navigation-patch'; +import { debugLog, whenDebugging } from 'core-app/shared/helpers/debug_output'; +import { TURBO_EVENTS } from './constants'; // Disable default turbo-drive for now as we don't need it for now AND it breaks angular routing Turbo.session.drive = false; // Start turbo Turbo.start(); +// Register logging of events +whenDebugging(() => { + TURBO_EVENTS.forEach((name:string) => { + document.addEventListener(name, (event) => { + debugLog(`[TURBO EVENT ${name}] %O`, event); + }); + }); +}); + // Register our own actions addTurboEventListeners(); registerDialogStreamAction();