-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Timeline Rendering on Zoom #3918
Conversation
Uses current scroll position instead of 0 when initially rendering timeline. Previously, the initial render would show ticks starting from 0 regardless of scroll position. Closes katspaugh#3782
Fix timeline flickering on zooming by removing rendering deferral
WalkthroughThe changes in this pull request modify the Changes
Assessment against linked issues
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Outside diff range and nitpick comments (1)
src/plugins/timeline.ts (1)
164-174
: Consider adding end-to-end tests for zoom operations.As mentioned in the PR objectives, this fix isn't covered by end-to-end tests. Given that this is a UI interaction bug, it would be valuable to add tests that verify timeline visibility during zoom operations.
Consider adding the following test scenarios:
- Timeline visibility check after zoom in/out
- Timeline marker positions at different zoom levels
- Cross-browser compatibility tests
Would you like me to help create these end-to-end tests or open a GitHub issue to track this task?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/plugins/timeline.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
src/plugins/timeline.ts (1)
164-174
: Verify the fix across different zoom levels and browser environments.Since the issue was specifically reported in Firefox and involves zoom operations, we should verify the fix across different scenarios.
if (!this.wavesurfer) return | ||
const scrollLeft = this.wavesurfer.getScroll() | ||
const scrollRight = scrollLeft + this.wavesurfer.getWidth() | ||
|
||
renderIfVisible(scrollLeft, scrollRight) | ||
|
||
this.subscriptions.push( | ||
this.wavesurfer.on('scroll', (_start, _end, scrollLeft, scrollRight) => { | ||
renderIfVisible(scrollLeft, scrollRight) | ||
}), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation aligns with PR objectives but needs additional error handling.
The changes correctly address the timeline disappearing issue by using the current scroll position instead of zero, and removing the setTimeout deferral that was causing flickering. However, there are a few considerations:
- The
getScroll()
andgetWidth()
calls should be wrapped in try-catch blocks as they might throw if wavesurfer is in an invalid state. - The scroll event subscription could leak if the renderIfVisible function throws.
Consider applying these defensive programming improvements:
if (!this.wavesurfer) return
-const scrollLeft = this.wavesurfer.getScroll()
-const scrollRight = scrollLeft + this.wavesurfer.getWidth()
+let scrollLeft = 0
+let scrollRight = 0
+try {
+ scrollLeft = this.wavesurfer.getScroll()
+ scrollRight = scrollLeft + this.wavesurfer.getWidth()
+} catch (error) {
+ console.warn('Timeline: Failed to get scroll position', error)
+ return
+}
renderIfVisible(scrollLeft, scrollRight)
-this.subscriptions.push(
- this.wavesurfer.on('scroll', (_start, _end, scrollLeft, scrollRight) => {
- renderIfVisible(scrollLeft, scrollRight)
- }),
-)
+try {
+ this.subscriptions.push(
+ this.wavesurfer.on('scroll', (_start, _end, scrollLeft, scrollRight) => {
+ renderIfVisible(scrollLeft, scrollRight)
+ }),
+ )
+} catch (error) {
+ console.warn('Timeline: Failed to subscribe to scroll events', error)
+}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (!this.wavesurfer) return | |
const scrollLeft = this.wavesurfer.getScroll() | |
const scrollRight = scrollLeft + this.wavesurfer.getWidth() | |
renderIfVisible(scrollLeft, scrollRight) | |
this.subscriptions.push( | |
this.wavesurfer.on('scroll', (_start, _end, scrollLeft, scrollRight) => { | |
renderIfVisible(scrollLeft, scrollRight) | |
}), | |
) | |
if (!this.wavesurfer) return | |
let scrollLeft = 0 | |
let scrollRight = 0 | |
try { | |
scrollLeft = this.wavesurfer.getScroll() | |
scrollRight = scrollLeft + this.wavesurfer.getWidth() | |
} catch (error) { | |
console.warn('Timeline: Failed to get scroll position', error) | |
return | |
} | |
renderIfVisible(scrollLeft, scrollRight) | |
try { | |
this.subscriptions.push( | |
this.wavesurfer.on('scroll', (_start, _end, scrollLeft, scrollRight) => { | |
renderIfVisible(scrollLeft, scrollRight) | |
}), | |
) | |
} catch (error) { | |
console.warn('Timeline: Failed to subscribe to scroll events', error) | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was instead thinking of:
const scrollLeft = this.wavesurfer?.getScroll() || 0
const scrollRight = scrollLeft + (this.wavesurfer?.getWidth() || 0)
However, shouldn't if (!this.wavesurfer) return
already guard against this, or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acieslewicz, you're absolutely right. The check if (!this.wavesurfer) return
ensures that this.wavesurfer
is defined, so calling getScroll()
and getWidth()
should be safe. Using optional chaining with fallback values, as you've suggested, is a clean and effective way to handle potential undefined values. Your approach makes sense, and the try-catch blocks may not be necessary here.
Thanks for clarifying!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks so much!
Short description
This should fix the timeline disappearing when Zooming in on the waveform. Resolves #3782
Implementation details
Instead of having virtualAppend initially call renderIfVisible with start = 0. Gets the current scroll window position and utilized it as the start instead. This means that the correct markers are rendered when the timeline is reinitialized after a zoom. Also removed the deferring of the initial call as it was causing timeline flickering while zooming.
How to test it
Create a window with a timeline. Change the cursor position to be something other than 0. Zoom in and out.
Screenshots
before-change.mp4
after-change.mp4
Checklist
Summary by CodeRabbit
wavesurfer
instance is initialized.