@@ -10,6 +10,7 @@ const LyricsText = React.forwardRef((props, textRef) => {
1010
1111 const { lyrics } = props
1212
13+ const currentTrackId = React . useRef ( null )
1314 const [ syncInterval , setSyncInterval ] = React . useState ( null )
1415 const [ currentLineIndex , setCurrentLineIndex ] = React . useState ( 0 )
1516 const [ visible , setVisible ] = React . useState ( false )
@@ -25,9 +26,7 @@ const LyricsText = React.forwardRef((props, textRef) => {
2526 } )
2627
2728 if ( lineIndex === - 1 ) {
28- if ( ! visible ) {
29- setVisible ( false )
30- }
29+ setVisible ( false )
3130
3231 return false
3332 }
@@ -70,8 +69,14 @@ const LyricsText = React.forwardRef((props, textRef) => {
7069
7170 //* Handle when current line index change
7271 React . useEffect ( ( ) => {
72+ console . debug ( "[lyrics] currentLineIndex" , currentLineIndex )
73+
7374 if ( currentLineIndex === 0 ) {
7475 setVisible ( false )
76+
77+ if ( textRef . current ) {
78+ textRef . current . scrollTop = 0
79+ }
7580 } else {
7681 setVisible ( true )
7782
@@ -87,9 +92,6 @@ const LyricsText = React.forwardRef((props, textRef) => {
8792 behavior : "smooth" ,
8893 block : "center" ,
8994 } )
90- } else {
91- // scroll to top
92- textRef . current . scrollTop = 0
9395 }
9496 }
9597 }
@@ -102,10 +104,16 @@ const LyricsText = React.forwardRef((props, textRef) => {
102104
103105 //* Handle when manifest object change, reset...
104106 React . useEffect ( ( ) => {
105- setVisible ( false )
106- setCurrentLineIndex ( 0 )
107- // set scroll top to 0
108- textRef . current . scrollTop = 0
107+ currentTrackId . current = playerState . track_manifest ?. id
108+
109+ if ( playerState . track_manifest ?. id !== currentTrackId . current ) {
110+ setVisible ( false )
111+ setCurrentLineIndex ( 0 )
112+
113+ if ( textRef . current ) {
114+ textRef . current . scrollTop = 0
115+ }
116+ }
109117 } , [ playerState . track_manifest ] )
110118
111119 React . useEffect ( ( ) => {
0 commit comments