hotfix(frontend): fix home redirect (3) (#11904)

### Changes 🏗️

Further improvements to LaunchDarkly initialisation and homepage
redirect...

### Checklist 📋

#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
- [x] Run the app locally with the flag disabled/enabled, and the
redirects work

---------

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
Co-authored-by: Ubbe <0ubbe@users.noreply.github.com>
This commit is contained in:
Ubbe
2026-01-30 20:40:46 +07:00
committed by GitHub
parent dbbff04616
commit cc4839bedb
2 changed files with 20 additions and 9 deletions

View File

@@ -1,11 +1,15 @@
import { redirect } from "next/navigation";
"use client";
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
import { useRouter } from "next/navigation";
import { useEffect } from "react";
/**
* Root page always redirects to /copilot.
* The /copilot page handles the feature flag check and redirects to /library if needed.
* This single-check approach avoids race conditions with LaunchDarkly initialization.
* See: SECRT-1845
*/
export default function Page() {
redirect("/copilot");
const router = useRouter();
useEffect(() => {
router.replace("/copilot");
}, [router]);
return <LoadingSpinner size="large" cover />;
}

View File

@@ -1,5 +1,6 @@
"use client";
import { LoadingSpinner } from "@/components/atoms/LoadingSpinner/LoadingSpinner";
import { useSupabase } from "@/lib/supabase/hooks/useSupabase";
import * as Sentry from "@sentry/nextjs";
import { LDProvider } from "launchdarkly-react-client-sdk";
@@ -15,7 +16,9 @@ export function LaunchDarklyProvider({ children }: { children: ReactNode }) {
const clientId = environment.getLaunchDarklyClientId();
const context = useMemo(() => {
if (isUserLoading || !user) {
if (isUserLoading) return;
if (!user) {
return {
kind: "user" as const,
key: "anonymous",
@@ -38,6 +41,10 @@ export function LaunchDarklyProvider({ children }: { children: ReactNode }) {
return <>{children}</>;
}
if (isUserLoading) {
return <LoadingSpinner size="large" cover />;
}
return (
<LDProvider
clientSideID={clientId ?? ""}