Sometimes when highlighting text and reloading the page, the target text is no longer highlighted but instead all text following it is highlighted to the end.
I don't have a clear individual replication path, but I copied my highlights from the localStorage to Chrome, Firefox and Edge and in all of them the same error happened.
By having the highlights and visiting the following sections:
I have identified that the error occurs within the highlightIsValid function of the utils.ts file on line 67, where the innerHTML of the first element of the dom_nodes array is readed but this array is empty because the validation of line 64 uses the statement if (!dom_nodes) return false; which only validates that it is not falsy but not its length.
Therefore it should be corrected by replacing this validation with:
export const highlightIsValid = (highlighter: Highlighter, highlight: HighlightSource) => {
/*other code*/
// if highlight has no DOM node, filter
if (!dom_node?.length) return false;
};
main
branch to see if this has already been fixed, in this file:Description of the problem:
Sometimes when highlighting text and reloading the page, the target text is no longer highlighted but instead all text following it is highlighted to the end.
I don't have a clear individual replication path, but I copied my highlights from the
localStorage
to Chrome, Firefox and Edge and in all of them the same error happened.By having the highlights and visiting the following sections:
The pages look like this:![image](https://github.com/cognitive-engineering-lab/rust-book/assets/100786328/542ad5a2-7d9c-40b2-80c2-c6b4a7b47f35)
And the following error appears in the console:![image](https://github.com/cognitive-engineering-lab/rust-book/assets/100786328/9c2e5baf-61ce-42a1-b8fc-65f8c14939f7)
Suggested fix:
I have identified that the error occurs within the
highlightIsValid
function of the utils.ts file on line 67, where theinnerHTML
of the first element of thedom_nodes
array is readed but this array is empty because the validation of line 64 uses the statementif (!dom_nodes) return false;
which only validates that it is not falsy but not its length.Therefore it should be corrected by replacing this validation with: