Skip to content

Commit

Permalink
fix: fix major search performance due to wrong marker element
Browse files Browse the repository at this point in the history
fixes #1109
  • Loading branch information
RomanHotsiy committed Mar 16, 2020
1 parent 7608800 commit 8c053cc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/ApiInfo/ApiInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
)) ||
null}
</StyledMarkdownBlock>
<Markdown source={store.spec.info.description} />
<Markdown source={store.spec.info.description} data-role="redoc-description" />
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
</MiddlePanel>
</Row>
Expand Down
4 changes: 3 additions & 1 deletion src/components/Markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ export type MarkdownProps = BaseMarkdownProps &
StylingMarkdownProps & {
source: string;
className?: string;
'data-role'?: string;
};

export class Markdown extends React.Component<MarkdownProps> {
render() {
const { source, inline, compact, className } = this.props;
const { source, inline, compact, className, 'data-role': dataRole } = this.props;
const renderer = new MarkdownRenderer();
return (
<SanitizedMarkdownHTML
html={renderer.renderMd(source)}
inline={inline}
compact={compact}
className={className}
data-role={dataRole}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/Markdown/SanitizedMdBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const StyledMarkdownSpan = StyledMarkdownBlock.withComponent('span');
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);

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

Expand All @@ -22,6 +22,7 @@ export function SanitizedMarkdownHTML(
dangerouslySetInnerHTML={{
__html: sanitize(options.untrustedSpec, props.html),
}}
data-role={props['data-role']}
{...props}
/>
)}
Expand Down
16 changes: 9 additions & 7 deletions src/services/AppStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
SECURITY_DEFINITIONS_JSX_NAME,
} from '../utils/openapi';

import { IS_BROWSER } from '../utils';

export interface StoreState {
menu: {
activeItemIdx: number;
Expand Down Expand Up @@ -134,16 +136,16 @@ export class AppStore {

const elements: Element[] = [];
for (let i = start; i < end; i++) {
let elem = this.menu.getElementAt(i);
const elem = this.menu.getElementAt(i);
if (!elem) {
continue;
}
if (this.menu.flatItems[i].type === 'section') {
elem = elem.parentElement!.parentElement;
}
if (elem) {
elements.push(elem);
}
elements.push(elem);
}

if (idx === -1 && IS_BROWSER) {
const $description = document.querySelector('[data-role="redoc-description"]');
if ($description) elements.push($description);
}

this.marker.addOnly(elements);
Expand Down

0 comments on commit 8c053cc

Please sign in to comment.