Core & UI: remove deprecated APIs

This commit is contained in:
Fuma Nama
2025-10-07 13:16:36 +08:00
parent d336b13034
commit 42f09c3c73
11 changed files with 36 additions and 210 deletions
+20
View File
@@ -0,0 +1,20 @@
---
'fumadocs-ui': major
'fumadocs-core': major
---
**Remove deprecated APIs**
- `fumadocs-ui/page`: `<DocsCategory />` removed.
- `<DocsPage />`: removed `breadcrumbs.full`.
- `fumadocs-core/search`:
- remove deprecated signature of `createFromSource()`: migrate to newer usage instead.
```ts
export function createFromSource<S extends LoaderOutput<LoaderConfig>>(
source: S,
pageToIndexFn?: (page: InferPageType<S>) => Awaitable<AdvancedIndex>,
options?: Omit<Options<S>, 'buildIndex'>,
): SearchAPI;
```
- remove deprecated parameters in `useSearch()`, pass them in the client object instead.
- `fumadocs-core/highlight`: remove deprecated `withPrerenderScript` and `loading` options from `useShiki()`.
+1 -13
View File
@@ -12,19 +12,7 @@ const promises: Record<string, Promise<ReactNode>> = {};
export function useShiki(
code: string,
options: HighlightOptions & {
/**
* @deprecated no longer pre-rendered using scripts.
*/
withPrerenderScript?: boolean;
/**
* Displayed before highlighter is loaded.
*
* @deprecated use React `Suspense` fallback instead.
*/
loading?: ReactNode;
},
options: HighlightOptions,
deps?: DependencyList,
): ReactNode {
const id = useId();
+1 -28
View File
@@ -76,35 +76,8 @@ export function useDocsSearch(
*/
allowEmpty?: boolean;
},
/**
* @deprecated pass to `client` object instead
*/
_locale?: string,
/**
* @deprecated pass to `client` object instead
*/
_tag?: string,
/**
* @deprecated pass to `client` object instead
*/
_delayMs = 100,
/**
* @deprecated pass to `client` object instead
*/
_allowEmpty = false,
/**
* @deprecated No longer used
*/
_key?: string,
): UseDocsSearch {
// handle deprecated params
const {
delayMs = _delayMs ?? 100,
allowEmpty = _allowEmpty ?? false,
...client
} = clientOptions;
client.tag ??= _tag;
client.locale ??= _locale;
const { delayMs = 100, allowEmpty = false, ...client } = clientOptions;
const [search, setSearch] = useState('');
const [results, setResults] = useState<SortedResult[] | 'empty'>('empty');
@@ -87,30 +87,11 @@ export function createFromSource<S extends LoaderOutput<LoaderConfig>>(
options?: Options<S>,
): SearchAPI;
/**
* @deprecated Use `createFromSource(source, options)` instead.
*/
export function createFromSource<S extends LoaderOutput<LoaderConfig>>(
source: S,
pageToIndexFn?: (page: InferPageType<S>) => Awaitable<AdvancedIndex>,
options?: Omit<Options<S>, 'buildIndex'>,
): SearchAPI;
export function createFromSource<S extends LoaderOutput<LoaderConfig>>(
source: S,
_buildIndexOrOptions?:
| ((page: InferPageType<S>) => Awaitable<AdvancedIndex>)
| Options<S>,
_options?: Omit<Options<S>, 'buildIndex'>,
options: Options<S> = {},
): SearchAPI {
const { buildIndex = defaultBuildIndex(source), ...options }: Options<S> = {
...(typeof _buildIndexOrOptions === 'function'
? {
buildIndex: _buildIndexOrOptions,
}
: _buildIndexOrOptions),
..._options,
};
const { buildIndex = defaultBuildIndex(source) } = options;
if (source._i18n) {
return createI18nSearchAPI('advanced', {
-6
View File
@@ -129,12 +129,6 @@ export interface AdvancedIndex {
id: string;
title: string;
description?: string;
/**
* @deprecated No longer used
*/
keywords?: string;
breadcrumbs?: string[];
/**
+2 -2
View File
@@ -61,9 +61,9 @@
"types": "./dist/layouts/shared/index.d.ts"
},
"./page": {
"node": "./dist/page.server.js",
"node": "./dist/page.js",
"import": "./dist/page.js",
"types": "./dist/page.server.d.ts"
"types": "./dist/page.d.ts"
},
"./provider": {
"import": "./dist/provider/index.js",
-61
View File
@@ -1,61 +0,0 @@
'use client';
// TODO: remove next major
import type { I18nProviderProps } from '@/provider/base';
import { usePathname, useRouter } from 'fumadocs-core/framework';
import { useMemo, useRef } from 'react';
import { defaultTranslations, I18nContext } from '@/contexts/i18n';
/**
* @deprecated legacy I18n Provider, use `<RootProvider i18n={...} />` instead
*/
export function I18nProvider({
locales = [],
locale,
onChange: _onChange,
onLocaleChange = _onChange,
...props
}: I18nProviderProps & {
/**
* @deprecated use `onLocaleChange` instead
*/
onChange?: I18nProviderProps['onLocaleChange'];
}) {
const router = useRouter();
const pathname = usePathname();
const onChange =
onLocaleChange ??
((value: string) => {
const segments = pathname.split('/').filter((v) => v.length > 0);
// If locale prefix hidden
if (segments[0] !== locale) {
segments.unshift(value);
} else {
segments[0] = value;
}
router.push(`/${segments.join('/')}`);
router.refresh();
});
const onChangeRef = useRef(onChange);
onChangeRef.current = onChange;
return (
<I18nContext.Provider
value={useMemo(
() => ({
locale,
locales,
text: {
...defaultTranslations,
...props.translations,
},
onChange: (v) => onChangeRef.current(v),
}),
[locale, locales, props.translations],
)}
>
{props.children}
</I18nContext.Provider>
);
}
-1
View File
@@ -4,7 +4,6 @@ import type { I18nConfig } from 'fumadocs-core/i18n';
export type { I18nProviderProps, Translations };
export { defaultTranslations } from './contexts/i18n';
export { I18nProvider } from './contexts/legacy-i18n';
export function defineI18nUI<Languages extends string>(
config: I18nConfig<Languages>,
-68
View File
@@ -1,68 +0,0 @@
import type { HTMLAttributes } from 'react';
import type { LoaderConfig, LoaderOutput, Page } from 'fumadocs-core/source';
import { getPageTreePeers, type Root } from 'fumadocs-core/page-tree';
import { Card, Cards } from '@/components/card';
import * as path from 'node:path';
/**
* @deprecated use https://fumadocs.dev/docs/ui/markdown#further-reading-section instead
*/
export function DocsCategory({
page,
from,
tree: forcedTree,
...props
}: HTMLAttributes<HTMLDivElement> & {
page: Page;
from: LoaderOutput<LoaderConfig>;
tree?: Root;
}) {
let tree;
if (forcedTree) {
tree = forcedTree;
} else if (from._i18n) {
const locale = page.locale ?? from._i18n.defaultLanguage;
tree = (from as LoaderOutput<LoaderConfig & { i18n: true }>).pageTree[
locale
];
} else {
tree = from.pageTree;
}
let items = getPageTreePeers(tree, page.url);
if (items.length === 0) {
const pages = from.getPages(page.locale);
items = pages
.filter(
(item) =>
path.dirname(item.path) === path.dirname(page.path) &&
item.path !== page.path,
)
.map((page) => ({
type: 'page',
name: page.data.title,
description: page.data.description,
url: page.url,
}));
}
if (items.length === 0) return null;
return (
<Cards {...props}>
{items.map((item) => (
<Card
key={item.url}
title={item.name}
description={item.description}
href={item.url}
/>
))}
</Cards>
);
}
export * from './page';
-8
View File
@@ -42,14 +42,6 @@ interface EditOnGitHubOptions
interface BreadcrumbOptions extends BreadcrumbProps {
enabled: boolean;
component: ReactNode;
/**
* Show the full path to the current page
*
* @defaultValue false
* @deprecated use `includePage` instead
*/
full?: boolean;
}
interface FooterOptions extends FooterProps {
+10 -2
View File
@@ -1,7 +1,15 @@
'use client';
// TODO: remove this, recommend `fumadocs-ui/provider/next` instead.
export { RootProvider } from './next';
console.warn(
'`fumadocs-ui/provider` export will be removed on v17, you can import from `fumadocs-ui/provider/next` instead.',
);
export {
/**
* @deprecated Import from `fumadocs-ui/provider/next` instead.
*/
RootProvider,
} from './next';
export { useI18n, I18nLabel } from '@/contexts/i18n';
export {