Skip to content

Commit 81da50f

Browse files
authored
fix: remove possible infinite loop in the changelog transformation (#1452)
In a recent `eslint` formatting PR (#1439), we changed the `void` returns to `return 0`. This causes `unified` to loop indefinitely in some cases (the visitor is expected to return `true / false` or **index of the next sibling** to be visited). This PR makes use of the exported `CONTINUE` symbol (alias for `true`) and the more verbose return syntax. Fixes the stalling documentation builds in Apify SDK for Python.
1 parent 4aee586 commit 81da50f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

apify-docs-theme/src/markdown.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const remarkParse = require('remark-parse');
22
const remarkStringify = require('remark-stringify');
33
const { unified } = require('unified');
4-
const { visitParents } = require('unist-util-visit-parents');
4+
const { visitParents, CONTINUE } = require('unist-util-visit-parents');
55

66
/**
77
* Bumps the headings levels in the markdown content. This function increases the depth
@@ -40,7 +40,7 @@ const linkifyUserTags = () => (tree) => {
4040

4141
const directParent = parents[parents.length - 1];
4242

43-
if (!match || directParent.type === 'link') return 0;
43+
if (!match || directParent.type === 'link') return CONTINUE;
4444

4545
const nodeIndexInParent = directParent.children.findIndex((x) => x === node);
4646

@@ -57,10 +57,10 @@ const linkifyUserTags = () => (tree) => {
5757
node.value = before;
5858
directParent.children.splice(nodeIndexInParent + 1, 0, link);
5959

60-
if (!after) return nodeIndexInParent + 2;
60+
if (!after) return [CONTINUE, nodeIndexInParent + 2];
6161

6262
directParent.children.splice(nodeIndexInParent + 2, 0, { type: 'text', value: `${ending}${after}` });
63-
return nodeIndexInParent + 3;
63+
return [CONTINUE, nodeIndexInParent + 3];
6464
});
6565
};
6666

@@ -75,7 +75,7 @@ const prettifyPRLinks = () => (tree) => {
7575
const prLinkRegex = /https:\/\/github.com\/[^\s]+\/pull\/(\d+)/g;
7676
const match = prLinkRegex.exec(node.value);
7777

78-
if (!match) return 0;
78+
if (!match) return CONTINUE;
7979

8080
const directParent = parents[parents.length - 1];
8181
const nodeIndexInParent = directParent.children.findIndex((x) => x === node);
@@ -92,10 +92,10 @@ const prettifyPRLinks = () => (tree) => {
9292
node.value = before;
9393

9494
directParent.children.splice(nodeIndexInParent + 1, 0, link);
95-
if (!after) return nodeIndexInParent + 1;
95+
if (!after) return [CONTINUE, nodeIndexInParent + 1];
9696

9797
directParent.children.splice(nodeIndexInParent + 2, 0, { type: 'text', value: after });
98-
return nodeIndexInParent + 2;
98+
return [CONTINUE, nodeIndexInParent + 2];
9999
});
100100
};
101101

0 commit comments

Comments
 (0)