Skip to content

Commit 8c053cc

Browse files
committed
fix: fix major search performance due to wrong marker element
fixes #1109
1 parent 7608800 commit 8c053cc

File tree

4 files changed

+15
-10
lines changed

4 files changed

+15
-10
lines changed

src/components/ApiInfo/ApiInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
100100
)) ||
101101
null}
102102
</StyledMarkdownBlock>
103-
<Markdown source={store.spec.info.description} />
103+
<Markdown source={store.spec.info.description} data-role="redoc-description" />
104104
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
105105
</MiddlePanel>
106106
</Row>

src/components/Markdown/Markdown.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ export type MarkdownProps = BaseMarkdownProps &
1717
StylingMarkdownProps & {
1818
source: string;
1919
className?: string;
20+
'data-role'?: string;
2021
};
2122

2223
export class Markdown extends React.Component<MarkdownProps> {
2324
render() {
24-
const { source, inline, compact, className } = this.props;
25+
const { source, inline, compact, className, 'data-role': dataRole } = this.props;
2526
const renderer = new MarkdownRenderer();
2627
return (
2728
<SanitizedMarkdownHTML
2829
html={renderer.renderMd(source)}
2930
inline={inline}
3031
compact={compact}
3132
className={className}
33+
data-role={dataRole}
3234
/>
3335
);
3436
}

src/components/Markdown/SanitizedMdBlock.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const StyledMarkdownSpan = StyledMarkdownBlock.withComponent('span');
1010
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);
1111

1212
export function SanitizedMarkdownHTML(
13-
props: StylingMarkdownProps & { html: string; className?: string },
13+
props: StylingMarkdownProps & { html: string; className?: string; 'data-role'?: string },
1414
) {
1515
const Wrap = props.inline ? StyledMarkdownSpan : StyledMarkdownBlock;
1616

@@ -22,6 +22,7 @@ export function SanitizedMarkdownHTML(
2222
dangerouslySetInnerHTML={{
2323
__html: sanitize(options.untrustedSpec, props.html),
2424
}}
25+
data-role={props['data-role']}
2526
{...props}
2627
/>
2728
)}

src/services/AppStore.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
SECURITY_DEFINITIONS_JSX_NAME,
1919
} from '../utils/openapi';
2020

21+
import { IS_BROWSER } from '../utils';
22+
2123
export interface StoreState {
2224
menu: {
2325
activeItemIdx: number;
@@ -134,16 +136,16 @@ export class AppStore {
134136

135137
const elements: Element[] = [];
136138
for (let i = start; i < end; i++) {
137-
let elem = this.menu.getElementAt(i);
139+
const elem = this.menu.getElementAt(i);
138140
if (!elem) {
139141
continue;
140142
}
141-
if (this.menu.flatItems[i].type === 'section') {
142-
elem = elem.parentElement!.parentElement;
143-
}
144-
if (elem) {
145-
elements.push(elem);
146-
}
143+
elements.push(elem);
144+
}
145+
146+
if (idx === -1 && IS_BROWSER) {
147+
const $description = document.querySelector('[data-role="redoc-description"]');
148+
if ($description) elements.push($description);
147149
}
148150

149151
this.marker.addOnly(elements);

0 commit comments

Comments
 (0)