diff --git a/.changeset/direct-site-search-same-domain.md b/.changeset/direct-site-search-same-domain.md index 7991ad3cb..9d8156b2c 100644 --- a/.changeset/direct-site-search-same-domain.md +++ b/.changeset/direct-site-search-same-domain.md @@ -2,4 +2,4 @@ "gitbook": patch --- -Retry direct site search on the site's own domain after a network error or timeout, and start on the same-domain proxy when `search.sameDomain` is enabled in site customization. +Retry direct site search on the site's own domain after a network error or timeout. diff --git a/packages/gitbook/src/components/Search/search-pass-store.test.ts b/packages/gitbook/src/components/Search/search-pass-store.test.ts index dc5f25354..1719ee2b0 100644 --- a/packages/gitbook/src/components/Search/search-pass-store.test.ts +++ b/packages/gitbook/src/components/Search/search-pass-store.test.ts @@ -1,5 +1,4 @@ import { afterEach, describe, expect, it, spyOn } from 'bun:test'; -import ReactDOM from 'react-dom'; import { createSearchPassStore } from './search-pass-store'; import type { DirectSearchProps } from '@/lib/search-results'; @@ -106,29 +105,6 @@ describe('createSearchPassStore', () => { ]); }); - it('uses the site proxy immediately and skips preconnect when sameDomain is true', async () => { - const preconnectSpy = spyOn(ReactDOM, 'preconnect').mockImplementation(() => undefined); - const fetchSpy = spyOn(globalThis, 'fetch') - .mockResolvedValueOnce(Response.json({ token: 'pass-1', expiresIn: 300_000 })) - .mockResolvedValueOnce(Response.json({ items: [] })); - restore = () => { - fetchSpy.mockRestore(); - preconnectSpy.mockRestore(); - }; - - const store = createSearchPassStore({ ...directSearch, sameDomain: true }); - await store.requestPass(); - - expect(preconnectSpy).not.toHaveBeenCalled(); - expect(await search(store)).toEqual({ type: 'results', results: [] }); - expect(fetchSpy.mock.calls.map(([url]) => url)).toEqual([directSearch.passURL, proxyURL]); - const init = fetchSpy.mock.calls[1]?.[1]; - expect(init).toMatchObject({ mode: 'same-origin', credentials: 'omit' }); - const headers = new Headers(init?.headers); - expect(headers.get('x-gitbook-search-pass')).toBe('pass-1'); - expect(headers.has('authorization')).toBe(false); - }); - it('stays on the route for the rest of the page after a 403', async () => { const { authorizations, fetchSpy } = mockFetch([403]); restore = () => fetchSpy.mockRestore(); diff --git a/packages/gitbook/src/components/Search/search-pass-store.ts b/packages/gitbook/src/components/Search/search-pass-store.ts index ed576479d..eb4c22c69 100644 --- a/packages/gitbook/src/components/Search/search-pass-store.ts +++ b/packages/gitbook/src/components/Search/search-pass-store.ts @@ -44,7 +44,7 @@ export type SearchPassStore = ReturnType; */ export function createSearchPassStore(directSearch: DirectSearchProps | undefined) { let state: SearchPassState = { status: 'none' }; - let useProxy = Boolean(directSearch?.sameDomain && directSearch.proxyURL); + let useProxy = false; let pendingRequest: Promise | null = null; const sendPassRequest = async () => { @@ -83,7 +83,7 @@ export function createSearchPassStore(directSearch: DirectSearchProps | undefine (current.status === 'none' && current.reason === '401') || (current.status === 'ready' && current.replacesRejectedPass), }; - if (!useProxy && !directSearch.sameDomain) { + if (!useProxy) { ReactDOM.preconnect(directSearch.apiURL, { crossOrigin: 'anonymous' }); } } else if (current.status === 'ready') { diff --git a/packages/gitbook/src/components/Search/search-props.ts b/packages/gitbook/src/components/Search/search-props.ts index 470f44ce4..d8c069da8 100644 --- a/packages/gitbook/src/components/Search/search-props.ts +++ b/packages/gitbook/src/components/Search/search-props.ts @@ -1,10 +1,4 @@ -import type { - SiteCustomizationSettings, - SiteExternalLink, - SiteSection, - SiteSectionGroup, - SiteSpace, -} from '@gitbook/api'; +import type { SiteExternalLink, SiteSection, SiteSectionGroup, SiteSpace } from '@gitbook/api'; import { hasMultipleSiteSections } from '../SiteSections'; import type { GitBookSiteContext } from '@/lib/context'; @@ -138,11 +132,8 @@ export function getDirectSearchProps(context: GitBookSiteContext): DirectSearchP return undefined; } - const customization: SiteCustomizationSettings & { - search?: { sameDomain?: boolean }; - } = context.customization; const { organizationId, siteId } = context.directSearch; - const props: DirectSearchProps = { + return { ...context.directSearch, spaces: getSearchSpaceLookup(context.structure), passURL: context.linker.toPathInSite('~gitbook/search-pass'), @@ -150,9 +141,4 @@ export function getDirectSearchProps(context: GitBookSiteContext): DirectSearchP `~gitbook/search-direct/orgs/${organizationId}/sites/${siteId}` ), }; - if (customization.search?.sameDomain === true) { - props.sameDomain = true; - } - - return props; } diff --git a/packages/gitbook/src/lib/search-results.ts b/packages/gitbook/src/lib/search-results.ts index 899f5094f..07648e688 100644 --- a/packages/gitbook/src/lib/search-results.ts +++ b/packages/gitbook/src/lib/search-results.ts @@ -42,7 +42,6 @@ export type DirectSearchProps = { organizationId: string; siteId: string; proxyURL?: string; - sameDomain?: boolean; linker: SiteLinkerInput; spaces: SearchSpaceLookup; /** Site route that hands out a search pass. */