diff --git a/packages/mdx/src/smooth-code/use-dimensions.tsx b/packages/mdx/src/smooth-code/use-dimensions.tsx index da8ea15b..217294d1 100644 --- a/packages/mdx/src/smooth-code/use-dimensions.tsx +++ b/packages/mdx/src/smooth-code/use-dimensions.tsx @@ -56,40 +56,43 @@ function useDimensions( code.next, focus.next ) + const lines = (code.prev || code.next!) .trimEnd() .split(newlineRe) const lineCount = lines.length + // avod setting the ref more than once https://github.com/code-hike/codehike/issues/232 + let prevLineRefSet = false const element = (
- {lines.map((line, i) => ( -
- {lineNumbers ? ( - - _{lineCount} - - ) : undefined} -
- {line} + {lines.map((line, i) => { + const ref = + !prevLineRefSet && line === prevLongestLine + ? prevLineRef + : undefined + prevLineRefSet = prevLineRefSet || ref != null + return ( +
+ {lineNumbers ? ( + + _{lineCount} + + ) : undefined} +
+ {line} +
-
- ))} + ) + })}
)