Skip to content

Commit 4cf9cdd

Browse files
authored
Fix ToC not re-rendering when linking to a variant from SearchResults (#2366)
1 parent 39406bb commit 4cf9cdd

File tree

4 files changed

+20
-38
lines changed

4 files changed

+20
-38
lines changed

src/components/Search/SearchModal.tsx

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -232,28 +232,23 @@ function SearchModalBody(
232232
</div>
233233
</div>
234234
{!state.ask || !withAsk ? (
235-
<>
236-
<SearchResults
237-
ref={resultsRef}
238-
spaceId={spaceId}
239-
revisionId={revisionId}
240-
parent={state.global ? parent : null}
241-
query={state.query}
242-
withAsk={withAsk}
243-
onSwitchToAsk={() => {
244-
onChangeQuery({
245-
ask: true,
246-
query: state.query,
247-
global: state.global,
248-
});
249-
}}
250-
onClose={onClose}
251-
>
252-
{parent && state.query ? (
253-
<SearchScopeToggle spaceTitle={spaceTitle} />
254-
) : null}
255-
</SearchResults>
256-
</>
235+
<SearchResults
236+
ref={resultsRef}
237+
spaceId={spaceId}
238+
revisionId={revisionId}
239+
parent={state.global ? parent : null}
240+
query={state.query}
241+
withAsk={withAsk}
242+
onSwitchToAsk={() => {
243+
onChangeQuery({
244+
ask: true,
245+
query: state.query,
246+
global: state.global,
247+
});
248+
}}
249+
>
250+
{parent && state.query ? <SearchScopeToggle spaceTitle={spaceTitle} /> : null}
251+
</SearchResults>
257252
) : null}
258253
{state.query && state.ask && withAsk ? (
259254
<SearchAskAnswer spaceId={spaceId} query={state.query} />

src/components/Search/SearchPageResultItem.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ export const SearchPageResultItem = React.forwardRef(function SearchPageResultIt
1111
query: string;
1212
item: ComputedPageResult;
1313
active: boolean;
14-
onClick: (to: string) => void;
1514
},
1615
ref: React.Ref<HTMLAnchorElement>,
1716
) {
18-
const { query, item, active, onClick } = props;
17+
const { query, item, active } = props;
1918

2019
return (
2120
<Link
2221
ref={ref}
2322
href={item.href}
24-
onClick={(event) => {
25-
event.preventDefault();
26-
onClick(item.href);
27-
}}
2823
className={tcls(
2924
'flex',
3025
'flex-row',

src/components/Search/SearchResults.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,10 @@ export const SearchResults = React.forwardRef(function SearchResults(
4343
parent: Site | Collection | null;
4444
withAsk: boolean;
4545
onSwitchToAsk: () => void;
46-
onClose: (to?: string) => void;
4746
},
4847
ref: React.Ref<SearchResultsRef>,
4948
) {
50-
const { children, query, spaceId, revisionId, parent, withAsk, onSwitchToAsk, onClose } = props;
49+
const { children, query, spaceId, revisionId, parent, withAsk, onSwitchToAsk } = props;
5150

5251
const language = useLanguage();
5352
const debounceTimeout = React.useRef<NodeJS.Timeout | null>(null);
@@ -211,7 +210,6 @@ export const SearchResults = React.forwardRef(function SearchResults(
211210
query={query}
212211
item={item}
213212
active={index === cursor}
214-
onClick={onClose}
215213
/>
216214
);
217215
}
@@ -252,7 +250,6 @@ export const SearchResults = React.forwardRef(function SearchResults(
252250
query={query}
253251
item={item}
254252
active={index === cursor}
255-
onClick={onClose}
256253
/>
257254
);
258255
}

src/components/Search/SearchSectionResultItem.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,15 @@ export const SearchSectionResultItem = React.forwardRef(function SearchSectionRe
1111
query: string;
1212
item: ComputedSectionResult;
1313
active: boolean;
14-
onClick: (to: string) => void;
1514
},
1615
ref: React.Ref<HTMLAnchorElement>,
1716
) {
18-
const { query, item, active, onClick } = props;
17+
const { query, item, active } = props;
1918

2019
return (
2120
<Link
2221
ref={ref}
2322
href={item.href}
24-
onClick={(event) => {
25-
event.preventDefault();
26-
onClick(item.href);
27-
}}
2823
className={tcls(
2924
'search-section-result-item',
3025
'[&:has(+:not(&))]:mb-6',

0 commit comments

Comments
 (0)