From 26037cf511d1536c5aee0b66ae6dd69aa916f782 Mon Sep 17 00:00:00 2001 From: Luca Sacchi Ricciardi Date: Tue, 7 Apr 2026 23:54:58 +0200 Subject: [PATCH] fix: move OnboardingProvider inside BrowserRouter to fix useLocation error The OnboardingProvider component uses useLocation() from react-router, but it was placed outside the BrowserRouter in the component tree. This caused the error: 'useLocation() may be used only in the context of a component.' Fixed by: 1. Creating a new RouterProviders wrapper component inside BrowserRouter 2. Moving OnboardingProvider, KeyboardShortcutsProvider, and CommandPalette inside the RouterProviders (which is inside BrowserRouter) 3. Keeping other providers (I18nProvider, ThemeProvider, QueryProvider, AuthProvider) outside BrowserRouter as they don't need router context This ensures all components that use router hooks are properly wrapped in the Router context. Frontend now renders correctly without JavaScript errors. --- frontend/src/App.tsx | 67 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 29 deletions(-) diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 8f31bc4..54eebb9 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -33,19 +33,14 @@ function ProtectedLayout() { ); } -// Wrapper for routes with providers +// Wrapper for routes with providers (outside Router) function AppProviders({ children }: { children: React.ReactNode }) { return ( - - - {children} - - - + {children} @@ -53,33 +48,47 @@ function AppProviders({ children }: { children: React.ReactNode }) { ); } +// Wrapper for providers that need Router context +function RouterProviders({ children }: { children: React.ReactNode }) { + return ( + + + {children} + + + + ); +} + function App() { return ( - }> - - {/* Public routes */} - } /> - } /> - - {/* Protected routes with layout */} - }> - } /> - } /> - } /> - } /> - } /> - } /> - } /> - - - {/* 404 */} - } /> - - + + }> + + {/* Public routes */} + } /> + } /> + + {/* Protected routes with layout */} + }> + } /> + } /> + } /> + } /> + } /> + } /> + } /> + + + {/* 404 */} + } /> + + + + - ); }