Skip to content

Commit 1743453

Browse files
committed
fix: add id attr to headers to work before react is loaded if ssr
1 parent 7eb477b commit 1743453

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

src/components/ContentItems/ContentItems.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ export class ContentItem extends React.Component<ContentItemProps> {
5959
export class TagItem extends React.Component<ContentItemProps> {
6060
render() {
6161
const { name, description } = this.props.item;
62+
const hash = this.props.item.getHash();
6263
return (
6364
<Row>
6465
<MiddlePanel key="middle">
65-
<H1>
66-
<ShareLink href={'#' + this.props.item.getHash()} />
66+
<H1 id={hash}>
67+
<ShareLink href={'#' + hash} />
6768
{name}
6869
</H1>
6970
{description !== undefined && <Markdown source={description} />}

src/components/Operation/Operation.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ export class Operation extends ComponentWithOptions<OperationProps> {
4444

4545
const { name: summary, description, deprecated } = operation;
4646
const pathInMiddle = this.options.pathInMiddlePanel;
47-
47+
const hash = operation.getHash();
4848
return (
4949
<OperationRow>
5050
<MiddlePanel>
51-
<H2>
52-
<ShareLink href={'#' + operation.getHash()} />
51+
<H2 id={hash}>
52+
<ShareLink href={'#' + hash} />
5353
{summary} {deprecated && <Badge type="warning"> Deprecated </Badge>}
5454
</H2>
5555
{pathInMiddle && <Endpoint operation={operation} inverted={true} />}

src/components/SecuritySchemes/SecuritySchemes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
8282
<div>
8383
{this.props.securitySchemes.schemes.map(scheme => (
8484
<div data-section-id={scheme.sectionId} key={scheme.id}>
85-
<H2>
85+
<H2 id={scheme.sectionId}>
8686
<ShareLink href={'#' + scheme.sectionId} />
8787
{scheme.id}
8888
</H2>

src/services/MarkdownRenderer.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ export class MarkdownRenderer {
9090
let id = this.currentTopHeading.id;
9191
return (
9292
`<a name="${id}"></a>` +
93-
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}">` +
93+
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}" id="${id}">` +
9494
`<a class="share-link" href="#${id}"></a>`
9595
);
9696
} else if (tokens[idx].hLevel === 2) {
9797
let { id } = this.saveHeading(content, this.currentTopHeading.items);
9898
return (
9999
`<a name="${id}"></a>` +
100-
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}">` +
100+
`<h${tokens[idx].hLevel} ${SECTION_ATTR}="${id}" id="${id}">` +
101101
`<a class="share-link" href="#${id}"></a>`
102102
);
103103
}

0 commit comments

Comments
 (0)