Files
outline/app/components/PageTitle.tsx
T
Tom MoorandClaude Opus 5 4b4c7d3281 chore: React 19 upgrade (#13562)
* React 19 upgrade

Bumps react and react-dom to 19.2.8, with the dependency changes React 19
requires: react-is 19, @types/react 19, @types/react-dom 19,
react-helmet-async 3 and react-avatar-editor 15 (which now ships its own
types). framer-motion moves to 13 — its v6 types reference React.ReactHTML,
removed from @types/react 19.

The type changes fall into a few classes:

- The global JSX namespace is gone, so JSX.Element becomes React.JSX.Element
  and the custom element declarations move into a module augmentation.
- useRef() now requires an initial value.
- A ref created with a null initial value is typed nullable, so consumers
  that accept one are widened to RefObject<T | null>.
- React.ReactChild was removed; tooltips take React.ReactNode.
- Ref callbacks may only return a cleanup function. react-dnd connectors
  return the connected node, so useDragRef and useDropRef wrap useDrag and
  useDrop and hand back a ref callback.

react-i18next stays on v12: i18next 23 drops compatibilityJSON "v3", which
would rewrite all 64 _plural keys across every locale.

outline-icons, oy-vey and react-waypoint have no release that lists React 19
as a peer. All three render correctly under it; the install reports them as
unmet peers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

* Remove react-helmet and forwardRef

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-18 22:22:50 -04:00

84 lines
2.1 KiB
TypeScript

import { observer } from "mobx-react";
import {
createContext,
useCallback,
useContext,
useLayoutEffect,
useState,
} from "react";
import type { ReactNode } from "react";
import env from "~/env";
import useStores from "~/hooks/useStores";
import { useSplitView } from "./SplitView/context";
import { useTeamContext } from "./TeamContext";
type FallbackProps = {
/** The title to use while no descendant PageTitle is mounted. */
title: string;
children?: ReactNode;
};
/**
* Renders a fallback document title that yields to any descendant PageTitle,
* so that only a single title element is ever present in the head.
*/
export function FallbackPageTitle({ title, children }: FallbackProps) {
const [claims, setClaims] = useState(0);
const handleClaim = useCallback(() => {
setClaims((count) => count + 1);
return () => setClaims((count) => count - 1);
}, []);
return (
<ClaimContext.Provider value={handleClaim}>
{claims === 0 && <title>{title}</title>}
{children}
</ClaimContext.Provider>
);
}
type Props = {
title: string;
favicon?: string;
};
const ClaimContext = createContext<(() => () => void) | undefined>(undefined);
const originalShortcutHref = document
.querySelector('link[rel="shortcut icon"]')
?.getAttribute("href") as string;
const PageTitle = ({ title, favicon }: Props) => {
const { auth } = useStores();
const team = useTeamContext() ?? auth.team;
const { isFocused } = useSplitView();
const claim = useContext(ClaimContext);
useLayoutEffect(
() => (isFocused ? claim?.() : undefined),
[claim, isFocused]
);
// Only the focused pane of a split view titles the tab, otherwise the panes
// compete and the title depends on which rendered last.
if (!isFocused) {
return null;
}
return (
<>
<title>
{team?.name ? `${title} - ${team.name}` : `${title} - ${env.APP_NAME}`}
</title>
<link
rel="shortcut icon"
type="image/png"
href={favicon ?? originalShortcutHref}
key={favicon ?? originalShortcutHref}
/>
</>
);
};
export default observer(PageTitle);