fix: prevent re-playing when click same track.#168
Conversation
…rrent track and downgrade `react-native-worklets` dependency.
SafeDep Report SummaryPackage Details
This report is generated by SafeDep Github App |
|
Caution Review failedThe pull request is closed. Walkthrough本次变更引入新的 Changes
Sequence Diagram(s)sequenceDiagram
participant User as 用户
participant Component as 播放列表组件
participant Hook as useCurrentTrackId
participant API as Orpheus API
participant Event as 事件系统
rect rgba(100,200,100,0.5)
Note over User,Hook: 初始化 / 同步当前曲目
Component->>Hook: 调用 useCurrentTrackId()
Hook->>API: getCurrentTrack()
API-->>Hook: 返回 currentTrack
Hook->>Hook: 提取并设置 trackId
Hook-->>Component: 提供 currentTrackId
end
rect rgba(100,150,200,0.5)
Note over User,Component: 用户点击曲目
User->>Component: 点击曲目项
Component->>Component: 比较 item.id 与 currentTrackId / currentTrackIdRef.current
alt 不同曲目
Component->>API: 请求播放新曲目
API->>Event: 触发 onTrackStarted
else 相同曲目
Component->>Component: 提前返回,跳过重播
end
end
rect rgba(200,150,100,0.5)
Note over Event,Hook: 曲目变更事件驱动更新
Event->>Hook: onTrackStarted / onTrackFinished
Hook->>API: 重新获取 getCurrentTrack()
API-->>Hook: 返回新的 currentTrack
Hook->>Hook: 更新 trackId 并触发组件重渲染
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/components/modals/PlayerQueueModal.tsx`:
- Around line 141-146: The switchTrackHandler can crash if queue changes and
queue[index] is undefined; modify the handler (switchTrackHandler) to first
retrieve const target = queue[index] (or check index >= 0 && index <
queue.length) and return early if target is falsy before accessing target.id or
calling Orpheus.skipTo(index), so you guard against out-of-bounds/undefined
entries and only call Orpheus.skipTo when target exists and target.id !==
currentTrackId.
In `@src/hooks/player/useCurrentTrackId.ts`:
- Around line 34-41: Add a second event listener for the 'onTrackFinished' event
in the same hook where Orpheus.addListener('onTrackStarted') is registered so
that fetchAndUpdate() runs when a track ends; create a subscription like the
existing sub for onTrackFinished, call void fetchAndUpdate() in its callback,
and ensure you remove that subscription in the cleanup along with sub and still
set isMounted = false—refer to Orpheus.addListener('onTrackStarted'),
fetchAndUpdate, and currentTrackIdRef to locate where to add and tear down the
new listener.
🧹 Nitpick comments (1)
src/hooks/player/useCurrentTrackId.ts (1)
15-23: 错误时不宜清空trackId,避免防重播失效
getCurrentTrack失败时直接setTrackId(undefined),可能在播放中出现“短暂失败 → 可重新播放同一首”的回退行为。建议保留上一次成功值,仅在成功获取时更新。♻️ 建议调整
- if (isMounted && currentRequestId === lastRequestIdRef.current) { - toastAndLogError('读取当前曲目信息失败', e, 'Hooks.useCurrentTrackId') - setTrackId(undefined) - } + if (isMounted && currentRequestId === lastRequestIdRef.current) { + toastAndLogError('读取当前曲目信息失败', e, 'Hooks.useCurrentTrackId') + // 保留上一次成功的 trackId,避免误放开防重播 + }
…ting on track finish, and add a null check in the player queue modal.
Co-authored-by: roitium <roitium@users.noreply.github.com> Co-authored-by: Roitium. <65794453+roitium@users.noreply.github.com> Co-authored-by: longlin li <gnulonglin@gmail.com> fix: prevent progress bar regression & add debounce to PlayButton (#153) fix: improve error message for failed lyric providers (BBPLAYER-5Q) (#157) fix: update PlaySlide info after song's change (#159) fix: prevent re-playing when click same track. (#168)

Closes #167
Summary by CodeRabbit
发布说明
Bug 修复
Chores
✏️ Tip: You can customize this high-level summary in your review settings.