mirror of
https://github.com/Redocly/redoc.git
synced 2025-02-19 19:30:32 +03:00
fix: fix major search performance due to wrong marker element
fixes #1109
This commit is contained in:
parent
7608800d0a
commit
8c053cc474
|
@ -100,7 +100,7 @@ export class ApiInfo extends React.Component<ApiInfoProps> {
|
||||||
)) ||
|
)) ||
|
||||||
null}
|
null}
|
||||||
</StyledMarkdownBlock>
|
</StyledMarkdownBlock>
|
||||||
<Markdown source={store.spec.info.description} />
|
<Markdown source={store.spec.info.description} data-role="redoc-description" />
|
||||||
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
|
{externalDocs && <ExternalDocumentation externalDocs={externalDocs} />}
|
||||||
</MiddlePanel>
|
</MiddlePanel>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
|
@ -17,11 +17,12 @@ export type MarkdownProps = BaseMarkdownProps &
|
||||||
StylingMarkdownProps & {
|
StylingMarkdownProps & {
|
||||||
source: string;
|
source: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
'data-role'?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Markdown extends React.Component<MarkdownProps> {
|
export class Markdown extends React.Component<MarkdownProps> {
|
||||||
render() {
|
render() {
|
||||||
const { source, inline, compact, className } = this.props;
|
const { source, inline, compact, className, 'data-role': dataRole } = this.props;
|
||||||
const renderer = new MarkdownRenderer();
|
const renderer = new MarkdownRenderer();
|
||||||
return (
|
return (
|
||||||
<SanitizedMarkdownHTML
|
<SanitizedMarkdownHTML
|
||||||
|
@ -29,6 +30,7 @@ export class Markdown extends React.Component<MarkdownProps> {
|
||||||
inline={inline}
|
inline={inline}
|
||||||
compact={compact}
|
compact={compact}
|
||||||
className={className}
|
className={className}
|
||||||
|
data-role={dataRole}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ const StyledMarkdownSpan = StyledMarkdownBlock.withComponent('span');
|
||||||
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);
|
const sanitize = (untrustedSpec, html) => (untrustedSpec ? DOMPurify.sanitize(html) : html);
|
||||||
|
|
||||||
export function SanitizedMarkdownHTML(
|
export function SanitizedMarkdownHTML(
|
||||||
props: StylingMarkdownProps & { html: string; className?: string },
|
props: StylingMarkdownProps & { html: string; className?: string; 'data-role'?: string },
|
||||||
) {
|
) {
|
||||||
const Wrap = props.inline ? StyledMarkdownSpan : StyledMarkdownBlock;
|
const Wrap = props.inline ? StyledMarkdownSpan : StyledMarkdownBlock;
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ export function SanitizedMarkdownHTML(
|
||||||
dangerouslySetInnerHTML={{
|
dangerouslySetInnerHTML={{
|
||||||
__html: sanitize(options.untrustedSpec, props.html),
|
__html: sanitize(options.untrustedSpec, props.html),
|
||||||
}}
|
}}
|
||||||
|
data-role={props['data-role']}
|
||||||
{...props}
|
{...props}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -18,6 +18,8 @@ import {
|
||||||
SECURITY_DEFINITIONS_JSX_NAME,
|
SECURITY_DEFINITIONS_JSX_NAME,
|
||||||
} from '../utils/openapi';
|
} from '../utils/openapi';
|
||||||
|
|
||||||
|
import { IS_BROWSER } from '../utils';
|
||||||
|
|
||||||
export interface StoreState {
|
export interface StoreState {
|
||||||
menu: {
|
menu: {
|
||||||
activeItemIdx: number;
|
activeItemIdx: number;
|
||||||
|
@ -134,16 +136,16 @@ export class AppStore {
|
||||||
|
|
||||||
const elements: Element[] = [];
|
const elements: Element[] = [];
|
||||||
for (let i = start; i < end; i++) {
|
for (let i = start; i < end; i++) {
|
||||||
let elem = this.menu.getElementAt(i);
|
const elem = this.menu.getElementAt(i);
|
||||||
if (!elem) {
|
if (!elem) {
|
||||||
continue;
|
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);
|
this.marker.addOnly(elements);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user