mirror of
https://github.com/okieselbach/AutopilotMonitor.git
synced 2026-10-23 20:26:10 +00:00
The sign-in return no longer prefetches the target route (D-366)
Measured in production with 300 ms latency, router.prefetch loaded only the route tree while auth/me was in flight, and the replace still fetched the route payload after auth/me: no gain on the critical path, one to three extra requests per sign-in return. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
import { useAuth } from "../../contexts/AuthContext";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useEffect, useRef } from "react";
|
||||
import { useEffect } from "react";
|
||||
import type { Route } from "next";
|
||||
import { landingTarget } from "../../lib/landingTarget";
|
||||
import { consumePostLoginReturnUrl, peekPostLoginReturnUrl } from "../../lib/postLoginReturn";
|
||||
@@ -10,7 +10,6 @@ import { portalHandoverUrl, shouldCrossOriginToPortal } from "../../lib/hostRout
|
||||
import { consumePendingRehome, getSelectedAuthApp, legacyConfigured, switchAuthApp, tryBeginRehome } from "../../lib/authApp";
|
||||
import { activeAuthApp } from "../../lib/msalConfig";
|
||||
import { trackEvent } from "../../lib/appInsights";
|
||||
import { trustedRoute } from "../../lib/routes";
|
||||
import { AUTH_PENDING_CLASS, hasAuthHint, holdsAuthOverlay } from "../../lib/authHint";
|
||||
|
||||
/**
|
||||
@@ -23,16 +22,6 @@ export function AuthGate() {
|
||||
const { isAuthenticated, isLoading, user, isActivationPending } = useAuth();
|
||||
const router = useRouter();
|
||||
|
||||
// Load the target's route payload while auth/me is still in flight, so the replace below commits
|
||||
// without a further round trip. Same-origin only: on the public host the target lives on portal.
|
||||
const targetPrefetched = useRef(false);
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated || targetPrefetched.current || shouldCrossOriginToPortal()) return;
|
||||
targetPrefetched.current = true;
|
||||
const returnUrl = peekPostLoginReturnUrl();
|
||||
router.prefetch(returnUrl ? trustedRoute(returnUrl) : "/dashboard");
|
||||
}, [isAuthenticated, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (isAuthenticated && !isLoading && user) {
|
||||
// Dual app-reg window: the sign-in that just completed ran on the other app than the
|
||||
|
||||
Reference in New Issue
Block a user