Skip to content

Commit 4a4e90a

Browse files
authored
chore(plugin-search): deprecates apiBasePath from config (#10953)
Continuation of #10632. The `apiBasePath` property in the Search Plugin config is unnecessary. This plugin reads directly from the Payload config for this property. Exposing it to the plugin's config was likely a mistake during sanitization before passing it through to the remaining files. This property was added to resolve the types, but as result, exposed it to the config unnecessarily. This PR marks this property with the deprecated flag to prevent breaking changes.
1 parent 136c90c commit 4a4e90a

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
2525
searchCollections,
2626
searchSlug,
2727
}) => {
28-
const apiBasePath = useConfig().config.routes.api
2928
const { closeModal, openModal } = useModal()
29+
30+
const { config } = useConfig()
31+
3032
const {
3133
i18n: { t },
3234
} = useTranslation()
35+
3336
const locale = useLocale()
3437
const router = useRouter()
3538

@@ -47,15 +50,16 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
4750
closeConfirmModal()
4851
setLoading(true)
4952

50-
const basePath = apiBasePath.endsWith('/') ? apiBasePath.slice(0, -1) : apiBasePath
51-
5253
try {
53-
const endpointRes = await fetch(`${basePath}/${searchSlug}/reindex?locale=${locale.code}`, {
54-
body: JSON.stringify({
55-
collections: reindexCollections,
56-
}),
57-
method: 'POST',
58-
})
54+
const endpointRes = await fetch(
55+
`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`,
56+
{
57+
body: JSON.stringify({
58+
collections: reindexCollections,
59+
}),
60+
method: 'POST',
61+
},
62+
)
5963

6064
const { message } = (await endpointRes.json()) as { message: string }
6165

@@ -65,13 +69,13 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
6569
toast.success(message)
6670
router.refresh()
6771
}
68-
} catch (err: unknown) {
72+
} catch (_err: unknown) {
6973
// swallow error, toast shown above
7074
} finally {
7175
setReindexCollections([])
7276
setLoading(false)
7377
}
74-
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, apiBasePath])
78+
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, config])
7579

7680
const handleShowConfirmModal = useCallback(
7781
(collections: string | string[] = searchCollections) => {

packages/plugin-search/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ export const searchPlugin =
3737

3838
const pluginConfig: SearchPluginConfigWithLocales = {
3939
// write any config defaults here
40-
apiBasePath: config.routes?.api,
4140
deleteDrafts: true,
4241
labels,
4342
locales,

packages/plugin-search/src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ export type BeforeSync = (args: {
3131
export type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]
3232

3333
export type SearchPluginConfig = {
34+
/**
35+
* @deprecated
36+
* This plugin gets the api route from the config directly and does not need to be passed in.
37+
* As long as you have `routes.api` set in your Payload config, the plugin will use that.
38+
* This property will be removed in the next major version.
39+
*/
3440
apiBasePath?: string
3541
beforeSync?: BeforeSync
3642
collections?: string[]

0 commit comments

Comments
 (0)