File tree 1 file changed +27
-24
lines changed
packages/mdx/src/smooth-code
1 file changed +27
-24
lines changed Original file line number Diff line number Diff line change @@ -56,40 +56,43 @@ function useDimensions(
56
56
code . next ,
57
57
focus . next
58
58
)
59
+
59
60
const lines = ( code . prev || code . next ! )
60
61
. trimEnd ( )
61
62
. split ( newlineRe )
62
63
63
64
const lineCount = lines . length
64
65
66
+ // avod setting the ref more than once https://github.com/code-hike/codehike/issues/232
67
+ let prevLineRefSet = false
65
68
const element = (
66
69
< code className = "ch-code-scroll-parent" >
67
70
< br />
68
- { lines . map ( ( line , i ) => (
69
- < div
70
- ref = {
71
- line === prevLongestLine
72
- ? prevLineRef
73
- : undefined
74
- }
75
- key = { i }
76
- >
77
- { lineNumbers ? (
78
- < span className = "ch-code-line-number" >
79
- _ { lineCount }
80
- </ span >
81
- ) : undefined }
82
- < div
83
- style = { {
84
- display : "inline-block" ,
85
- // leftPad
86
- marginLeft : 16 ,
87
- } }
88
- >
89
- < span > { line } </ span >
71
+ { lines . map ( ( line , i ) => {
72
+ const ref =
73
+ ! prevLineRefSet && line === prevLongestLine
74
+ ? prevLineRef
75
+ : undefined
76
+ prevLineRefSet = prevLineRefSet || ref != null
77
+ return (
78
+ < div ref = { ref } key = { i } >
79
+ { lineNumbers ? (
80
+ < span className = "ch-code-line-number" >
81
+ _ { lineCount }
82
+ </ span >
83
+ ) : undefined }
84
+ < div
85
+ style = { {
86
+ display : "inline-block" ,
87
+ // leftPad
88
+ marginLeft : 16 ,
89
+ } }
90
+ >
91
+ < span > { line } </ span >
92
+ </ div >
90
93
</ div >
91
- </ div >
92
- ) ) }
94
+ )
95
+ } ) }
93
96
< br />
94
97
</ code >
95
98
)
You can’t perform that action at this time.
0 commit comments