From 693b652d38398eff9f7463088c84186710d45667 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Thu, 24 Apr 2025 11:41:31 -0600 Subject: [PATCH] change prevent navigation to actually drop listener --- api/makefile | 5 +- web/package-lock.json | 8 +-- web/package.json | 2 +- .../ui/layouts/PreventNavigation.tsx | 61 +++++++------------ 4 files changed, 29 insertions(+), 47 deletions(-) diff --git a/api/makefile b/api/makefile index e4a8aeb1f..44a6aacb7 100644 --- a/api/makefile +++ b/api/makefile @@ -17,6 +17,7 @@ stop: pkill ollama fast: - export RUST_LOG=debug - export CARGO_INCREMENTAL=1 + cd .. && docker compose up -d redis && cd api && \ + export RUST_LOG=debug && \ + export CARGO_INCREMENTAL=1 && \ nice cargo watch -C server -x run \ No newline at end of file diff --git a/web/package-lock.json b/web/package-lock.json index 3558766af..fb6261c49 100644 --- a/web/package-lock.json +++ b/web/package-lock.json @@ -68,7 +68,7 @@ "next-themes": "^0.4.6", "papaparse": "^5.5.2", "pluralize": "^8.0.0", - "posthog-js": "^1.236.5", + "posthog-js": "^1.236.6", "prettier": "^3.5.3", "prettier-plugin-tailwindcss": "^0.6.11", "react": "^18", @@ -17986,9 +17986,9 @@ "license": "MIT" }, "node_modules/posthog-js": { - "version": "1.236.5", - "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.236.5.tgz", - "integrity": "sha512-2FrWVZwcLyeZAtdDckJaCfsk9m6DMdr/nVPVSqzF7yvm9pDsdbkvB3A16iqRj5L3EcqV2xWOcv8xWmKgdnNnqA==", + "version": "1.236.6", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.236.6.tgz", + "integrity": "sha512-IX4fkn3HCK+ObdHr/AuWd+Ks7bgMpRpOQB93b5rDJAWkG4if4xFVUn5pgEjyCNeOO2GM1ECnp08q9tYNYEfwbA==", "license": "MIT", "dependencies": { "core-js": "^3.38.1", diff --git a/web/package.json b/web/package.json index 7598e960f..30466af0c 100644 --- a/web/package.json +++ b/web/package.json @@ -77,7 +77,7 @@ "next-themes": "^0.4.6", "papaparse": "^5.5.2", "pluralize": "^8.0.0", - "posthog-js": "^1.236.5", + "posthog-js": "^1.236.6", "prettier": "^3.5.3", "prettier-plugin-tailwindcss": "^0.6.11", "react": "^18", diff --git a/web/src/components/ui/layouts/PreventNavigation.tsx b/web/src/components/ui/layouts/PreventNavigation.tsx index 44291981f..66a5c3de2 100644 --- a/web/src/components/ui/layouts/PreventNavigation.tsx +++ b/web/src/components/ui/layouts/PreventNavigation.tsx @@ -38,23 +38,24 @@ export const PreventNavigation: React.FC = React.memo( */ const handleClick = useMemoizedFn((event: MouseEvent) => { let originalTarget = event.target as HTMLElement; - let target = event.target as HTMLElement; - let href: string | null = null; let originalEvent = event; - // Traverse up the DOM tree looking for an anchor tag with href - while (target && !href) { - if (target instanceof HTMLAnchorElement && target.href) { - href = target.href; - break; - } - target = target.parentElement as HTMLElement; - } - - // Check if we're navigating to the same URL - if so, allow the navigation - if (href && new URL(href).pathname === window.location.pathname) { - return; // Allow navigation to the same URL - } + const newEvent = new MouseEvent('click', { + bubbles: true, + cancelable: true, + view: window, + detail: originalEvent.detail, + screenX: originalEvent.screenX, + screenY: originalEvent.screenY, + clientX: originalEvent.clientX, + clientY: originalEvent.clientY, + ctrlKey: originalEvent.ctrlKey, + altKey: originalEvent.altKey, + shiftKey: originalEvent.shiftKey, + metaKey: originalEvent.metaKey, + button: originalEvent.button, + buttons: originalEvent.buttons + }); if (isDirty) { event.preventDefault(); @@ -75,24 +76,6 @@ export const PreventNavigation: React.FC = React.memo( originalTarget.onclick = null; } - // Create a new click event - const newEvent = new MouseEvent('click', { - bubbles: true, - cancelable: true, - view: window, - detail: originalEvent.detail, - screenX: originalEvent.screenX, - screenY: originalEvent.screenY, - clientX: originalEvent.clientX, - clientY: originalEvent.clientY, - ctrlKey: originalEvent.ctrlKey, - altKey: originalEvent.altKey, - shiftKey: originalEvent.shiftKey, - metaKey: originalEvent.metaKey, - button: originalEvent.button, - buttons: originalEvent.buttons - }); - // Dispatch the event directly on the original target originalTarget.dispatchEvent(newEvent); @@ -100,16 +83,14 @@ export const PreventNavigation: React.FC = React.memo( if (clickHandlers) { originalTarget.onclick = clickHandlers; } - - // Re-attach our listeners after a short delay - setTimeout(() => { - document.querySelectorAll('a').forEach((link) => { - link.addEventListener('click', handleClick); - }); - }, 50); }; setLeavingPage(true); + } else { + document.querySelectorAll('a').forEach((link) => { + link.removeEventListener('click', handleClick); + }); + originalTarget.dispatchEvent(newEvent); } });