Phase 8, third batch: the three root components and both layouts. All five emit byte-identical JavaScript and the production bundle is byte-identical to3d5f54b. Small batch, and almost all of it was the rename. `ScrollToTop`, `UserNotRegisteredError` and both layouts take no props at all - the layouts render through `<Outlet />` - so inference already described them. `ProtectedRoute` gains the only real interface, and it clears a standing error. Both its props have fallbacks - `fallback` defaults to a spinner and `unauthenticatedElement` falls through `??` to the login redirect - and its one call site is a bare `<ProtectedRoute />` in `App.jsx`. Typed optional, which is what the defaults already said, that call site stops being an error: tsc goes 22 -> 21 with nothing introduced. The auth boundary itself is untouched. The `authError.type === 'user_not_registered'` branch, the `<Navigate to="/admin/login" state={{ from }}>` redirect and the `isLoadingAuth || !authChecked` gate are all exactly as they were - which matters, because `AdminLayout` is one of the files `skill-check.mjs` reads as source text, and it is read through the resolver added in02a2ab0. Verified: tsc 22 -> 21, set-difference showing one removed and none added; zero errors in any of the five; all five emit byte-identical JavaScript; production bundle byte-identical; npm test 1684/1691 with the same seven failures; Owliver baseline 59/59; lint 0 errors; baseline artifacts untouched. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HBG1wnuRfJKCstGB8Fekr8
34 lines
805 B
TypeScript
34 lines
805 B
TypeScript
import { useEffect } from "react";
|
|
import { useLocation, useNavigationType } from "react-router-dom";
|
|
|
|
const getHashId = (hash) => {
|
|
const rawId = hash.slice(1);
|
|
|
|
try {
|
|
return decodeURIComponent(rawId);
|
|
} catch {
|
|
return rawId;
|
|
}
|
|
};
|
|
|
|
export default function ScrollToTop() {
|
|
const { pathname, hash } = useLocation();
|
|
const navigationType = useNavigationType();
|
|
|
|
useEffect(() => {
|
|
if (navigationType === "POP") return;
|
|
|
|
if (hash) {
|
|
const id = getHashId(hash);
|
|
const timer = window.setTimeout(() => {
|
|
document.getElementById(id)?.scrollIntoView({ behavior: "smooth" });
|
|
}, 50);
|
|
return () => window.clearTimeout(timer);
|
|
}
|
|
|
|
window.scrollTo({ top: 0, left: 0, behavior: "instant" });
|
|
}, [pathname, hash, navigationType]);
|
|
|
|
return null;
|
|
}
|