Skip to content

Commit 7f03b94

Browse files
authored
Fix an issue where recommended questions werent using the current siteSpace context (#3559)
1 parent f0cf060 commit 7f03b94

File tree

6 files changed

+19
-16
lines changed

6 files changed

+19
-16
lines changed

bun.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@
246246
"react-dom": "^19.0.0",
247247
},
248248
"catalog": {
249-
"@gitbook/api": "^0.133.0",
249+
"@gitbook/api": "^0.134.0",
250250
},
251251
"packages": {
252252
"@ai-sdk/provider": ["@ai-sdk/[email protected]", "", { "dependencies": { "json-schema": "^0.4.0" } }, "sha512-0M+qjp+clUD0R1E5eWQFhxEvWLNaOtGQRUaBn8CUABnSKredagq92hUS9VjOzGsTm37xLfpaxl97AVtbeOsHew=="],
@@ -611,7 +611,7 @@
611611

612612
"@fortawesome/fontawesome-svg-core": ["@fortawesome/[email protected]", "", { "dependencies": { "@fortawesome/fontawesome-common-types": "6.6.0" } }, "sha512-KHwPkCk6oRT4HADE7smhfsKudt9N/9lm6EJ5BVg0tD1yPA5hht837fB87F8pn15D8JfTqQOjhKTktwmLMiD7Kg=="],
613613

614-
"@gitbook/api": ["@gitbook/api@0.133.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-Xi/A8NROQIj1haDA2XYr9b2+suUviyEVjplSslmwA2HyZnFNlkTaB1W0CwpVrZF8FZsfi3fZekQECOF34RLDDA=="],
614+
"@gitbook/api": ["@gitbook/api@0.134.0", "", { "dependencies": { "event-iterator": "^2.0.0", "eventsource-parser": "^3.0.0" } }, "sha512-WMdLsA0ZOTbOyoloevPs0qa/VR2xmfp+YB6T/a2o8fkFUv5fMXxDVfCAcIxB2q9NCmkriMSCohWKmxLfz44s6w=="],
615615

616616
"@gitbook/cache-tags": ["@gitbook/cache-tags@workspace:packages/cache-tags"],
617617

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"workspaces": {
3535
"packages": ["packages/*"],
3636
"catalog": {
37-
"@gitbook/api": "^0.133.0"
37+
"@gitbook/api": "^0.134.0"
3838
}
3939
},
4040
"patchedDependencies": {

packages/gitbook/src/components/Search/SearchContainer.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { SearchScopeToggle } from './SearchScopeToggle';
1616
import { useSearch } from './useSearch';
1717

1818
interface SearchContainerProps {
19-
spaceId: string;
19+
siteSpaceId: string;
2020
spaceTitle: string;
2121
isMultiVariants: boolean;
2222
aiMode: CustomizationAIMode;
@@ -27,7 +27,7 @@ interface SearchContainerProps {
2727
* Client component to render the search input and results.
2828
*/
2929
export function SearchContainer(props: SearchContainerProps) {
30-
const { spaceId, spaceTitle, isMultiVariants, aiMode, className } = props;
30+
const { siteSpaceId, spaceTitle, isMultiVariants, aiMode, className } = props;
3131

3232
const withAIChat = aiMode === CustomizationAIMode.Assistant;
3333
const [state, setSearchState] = useSearch(withAIChat);
@@ -151,7 +151,7 @@ export function SearchContainer(props: SearchContainerProps) {
151151
query={normalizedQuery}
152152
global={state?.global ?? false}
153153
aiMode={aiMode}
154-
spaceId={spaceId}
154+
siteSpaceId={siteSpaceId}
155155
/>
156156
) : null}
157157
{showAsk ? <SearchAskAnswer query={normalizedAsk} /> : null}

packages/gitbook/src/components/Search/SearchResults.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ export const SearchResults = React.forwardRef(function SearchResults(
5252
query: string;
5353
global: boolean;
5454
aiMode: CustomizationAIMode;
55-
spaceId: string;
55+
siteSpaceId: string;
5656
},
5757
ref: React.Ref<SearchResultsRef>
5858
) {
59-
const { children, query, aiMode, global, spaceId } = props;
59+
const { children, query, aiMode, global, siteSpaceId } = props;
6060

6161
const language = useLanguage();
6262
const trackEvent = useTrackEvent();
@@ -77,9 +77,12 @@ export const SearchResults = React.forwardRef(function SearchResults(
7777
return;
7878
}
7979

80-
if (cachedRecommendedQuestions.has(spaceId)) {
81-
const results = cachedRecommendedQuestions.get(spaceId);
82-
assert(results, `Cached recommended questions should be set for space ${spaceId}`);
80+
if (cachedRecommendedQuestions.has(siteSpaceId)) {
81+
const results = cachedRecommendedQuestions.get(siteSpaceId);
82+
assert(
83+
results,
84+
`Cached recommended questions should be set for site-space ${siteSpaceId}`
85+
);
8386
setResultsState({ results, fetching: false });
8487
return;
8588
}
@@ -98,7 +101,7 @@ export const SearchResults = React.forwardRef(function SearchResults(
98101
return;
99102
}
100103

101-
const response = await streamRecommendedQuestions(spaceId);
104+
const response = await streamRecommendedQuestions({ siteSpaceId });
102105
for await (const entry of readStreamableValue(response.stream)) {
103106
if (!entry) {
104107
continue;
@@ -115,7 +118,7 @@ export const SearchResults = React.forwardRef(function SearchResults(
115118
id: question,
116119
question,
117120
});
118-
cachedRecommendedQuestions.set(spaceId, recommendedQuestions);
121+
cachedRecommendedQuestions.set(siteSpaceId, recommendedQuestions);
119122

120123
if (!cancelled) {
121124
setResultsState({ results: [...recommendedQuestions], fetching: false });

packages/gitbook/src/components/Search/server-actions.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export async function streamAskQuestion({
194194
* Stream a list of suggested questions for the site.
195195
* Optionally scoped to a specific space.
196196
*/
197-
export async function streamRecommendedQuestions(spaceId?: string) {
197+
export async function streamRecommendedQuestions(args: { siteSpaceId?: string }) {
198198
return traceErrorOnly('Search.streamRecommendedQuestions', async () => {
199199
const siteURLData = await getSiteURLDataFromMiddleware();
200200
const context = await getServerActionBaseContext();
@@ -209,7 +209,7 @@ export async function streamRecommendedQuestions(spaceId?: string) {
209209
siteURLData.organization,
210210
siteURLData.site,
211211
{
212-
spaceId,
212+
siteSpaceId: args.siteSpaceId,
213213
}
214214
);
215215

packages/gitbook/src/components/SpaceLayout/SpaceLayout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export function SpaceLayout(props: {
6262
aiMode={aiMode}
6363
isMultiVariants={siteSpaces.length > 1}
6464
spaceTitle={siteSpace.title}
65-
spaceId={siteSpace.space.id}
65+
siteSpaceId={siteSpace.id}
6666
/>
6767
</React.Suspense>
6868
{aiMode === CustomizationAIMode.Assistant ? (

0 commit comments

Comments
 (0)