You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[v2] line-highlight loses its position when line-numbers registers after it #4137
line-highlight renders a 0px-tall highlight with no top when line-numbers is loaded after it.
<!doctype html><scripttype="importmap">{"imports": {"prismjs": "https://cdn.jsdelivr.net/npm/prismjs@2.0.0-alpha.1/dist/index.js","prismjs/": "https://cdn.jsdelivr.net/npm/prismjs@2.0.0-alpha.1/dist/"}}</script><script>globalThis.Prism={manual: true};</script><linkrel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@2.0.0-alpha.1/dist/plugins/line-numbers.css" /><linkrel="stylesheet" href="https://cdn.jsdelivr.net/npm/prismjs@2.0.0-alpha.1/dist/plugins/line-highlight.css" /><preclass="line-numbers" data-line="2"><codeclass="language-js">let a = 1;
let b = 2;
let c = 3;</code></pre><scripttype="module">importPrismfrom"prismjs";awaitimport("prismjs/plugins/line-highlight.js");awaitimport("prismjs/plugins/line-numbers.js");Prism.highlightAll();console.log(document.querySelector(".line-highlight").getAttribute("style"));</script>
Expected: top: 15px; height: 15px; width: … (what swapping the two imports prints)
Actual: width: 929px;, so line 2 is not highlighted
Both plugins use the complete hook, which runs in registration order. line-highlight asks line-numbers for the row of each line (lineNumbers.getLine(pre, start)), but the rows don't exist yet, so startNode is undefined and top/height are never set.
With data-prism-plugins="line-numbers, line-highlight" the order depends on which file finishes loading first, so the bug is intermittent. line-highlight declares optional: 'line-numbers', but the plugin registry doesn't use optional to order effects the way languages do.
Activity