fix: fix major search performance due to wrong marker element

fixes #1109
This commit is contained in:
Roman Hotsiy 2020-03-16 16:38:14 +02:00
parent 7608800d0a
commit 8c053cc474
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 15 additions and 10 deletions

View File

@ -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>

View File

@ -17,11 +17,12 @@ 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
@ -29,6 +30,7 @@ export class Markdown extends React.Component<MarkdownProps> {
inline={inline}
compact={compact}
className={className}
data-role={dataRole}
/>
);
}

View File

@ -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;
@ -22,6 +22,7 @@ export function SanitizedMarkdownHTML(
dangerouslySetInnerHTML={{
__html: sanitize(options.untrustedSpec, props.html),
}}
data-role={props['data-role']}
{...props}
/>
)}

View File

@ -18,6 +18,8 @@ import {
SECURITY_DEFINITIONS_JSX_NAME,
} from '../utils/openapi';
import { IS_BROWSER } from '../utils';
export interface StoreState {
menu: {
activeItemIdx: number;
@ -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);