Skip to content

Commit e52c8c7

Browse files
fix(core): make DocumentTitle tolerate missing BreadcrumbOverrideProvider
DocumentTitle renders in the root route element, which router tests mount without the AppShell provider stack. Read the breadcrumb overrides via a non-throwing useBreadcrumbOverrideOptional so the component degrades gracefully (no overrides) instead of crashing the router when the provider is absent. No behaviour change under AppShell, which always mounts BreadcrumbOverrideProvider. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 2eb01b4 commit e52c8c7

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

packages/core/src/components/document-title.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect } from "react";
22
import { useAppShellConfig } from "@/contexts/appshell-context";
3-
import { useBreadcrumbOverride } from "@/contexts/breadcrumb-context";
3+
import { useBreadcrumbOverrideOptional } from "@/contexts/breadcrumb-context";
44
import { usePathSegments } from "@/components/dynamic-breadcrumb";
55

66
const SEPARATOR = " · ";
@@ -25,13 +25,13 @@ const SEPARATOR = " · ";
2525
export const DocumentTitle = () => {
2626
const { title: appTitle } = useAppShellConfig();
2727
const { basePath, segments } = usePathSegments();
28-
const { overrides } = useBreadcrumbOverride();
28+
const overrides = useBreadcrumbOverrideOptional()?.overrides;
2929

3030
const leaf = segments.at(-1);
3131
let pageTitle: string | undefined;
3232
if (leaf) {
3333
const leafFullPath = basePath ? `/${basePath}/${leaf.path}` : `/${leaf.path}`;
34-
pageTitle = overrides.get(leafFullPath) ?? leaf.title;
34+
pageTitle = overrides?.get(leafFullPath) ?? leaf.title;
3535
}
3636

3737
const nextTitle = [pageTitle, appTitle].filter(Boolean).join(SEPARATOR);

packages/core/src/contexts/breadcrumb-context.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ export const useBreadcrumbOverride = () => {
4242
}
4343
return context;
4444
};
45+
46+
/**
47+
* Like {@link useBreadcrumbOverride} but returns `null` instead of throwing when
48+
* no `BreadcrumbOverrideProvider` is mounted. For consumers that should degrade
49+
* gracefully without overrides (e.g. components rendered in the router without
50+
* the full AppShell provider stack).
51+
*/
52+
export const useBreadcrumbOverrideOptional = () => useContext(BreadcrumbOverrideContext);

0 commit comments

Comments
 (0)