feat(small): Fix Spotify Polling crash and cleanup UI slop#9447
feat(small): Fix Spotify Polling crash and cleanup UI slop#9447
Conversation
This commit implements an Optimistic UI pattern for Spotify volume and playback controls to resolve state contention ("snap-back" issue) and enhance user experience in gym environments.
Key changes:
- Implemented a 2s synchronization lock in `SpotifyControls.tsx` using `lastUserInteractionRef` to ignore authoritative server state immediately after user interaction.
- Replaced debounced volume updates with throttled (200ms) "live" updates for a more responsive feel.
- Enhanced `SpotifyPolling` service to immediately broadcast optimistic state updates for PLAY/PAUSE commands.
- Reduced re-polling delay from 500ms to 300ms for faster authoritative sync.
- Improved accessibility in `VolumeSlider.tsx` with larger touch targets (20-28px thumbs) and `aria-valuetext` support.
- Updated unit tests to verify the synchronization lock logic using fake timers.
Co-authored-by: arii <342438+arii@users.noreply.github.com>
- Implemented `useSpotifyPlayback`, `useSpotifyVolume`, and `useSpotifyDeviceSync` hooks. - Resolved Spotify volume 'snap-back' issues with client-side interaction locks. - Enhanced backend `SpotifyPolling` with immediate optimistic broadcasts and stabilization windows. - **Security & Stability**: Hardened `spotifyPolling.ts` with safe property access for playback state. - **CI/CD Consistency**: Synchronized `pnpm` (9.15.9) and Node.js versions across all workflows. - **Test Optimization**: Introduced `mockWithVolume` helper in `SpotifyControls.test.tsx` to reduce boilerplate. - **Accessibility**: Improved `VolumeSlider` with 44px touch targets and ARIA live region support. - All quality gates (lint, type-check, knip, unit tests) passing. Co-authored-by: arii <342438+arii@users.noreply.github.com>
- Added optional chaining and existence checks to `services/spotifyPolling.ts` to prevent crashes when `this.state.playback` is not initialized. - Removed redundant `lastUserInteractionRef.current` assignment in `SpotifyControls.tsx`. - Removed repetitive slop comments in `SpotifyControls.tsx`. - Extracted a helper function (`mockSpotifyWithVolume`) in `SpotifyControls.test.tsx` to reduce mock data repetition. Co-authored-by: arii <342438+arii@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
- Implemented `useSpotifyPlayback`, `useSpotifyVolume`, and `useSpotifyDeviceSync` hooks. - Resolved Spotify volume 'snap-back' issues with client-side interaction locks. - Enhanced backend `SpotifyPolling` with immediate optimistic broadcasts and stabilization windows. - Hardened `spotifyPolling.ts` with safe property access for playback state to prevent potential crashes. - Synchronized `pnpm` (9.15.9) and Node.js versions across all GitHub Actions workflows. - Optimized unit tests in `SpotifyControls.test.tsx` by introducing `mockWithVolume` helper and fixing lint issues. - Improved `VolumeSlider` with 44px touch targets and ARIA live region support. - Verified all quality gates (lint, type-check, knip, unit tests) pass. Co-authored-by: arii <342438+arii@users.noreply.github.com>
…o spotify-optimistic-ui-refactor-2327602000982603155-3337824891126205794
- Removed unused `SPOTIFY_BRAND_COLOR` and `VOLUME_SLIDER_SX` from `SpotifyControls.tsx`. Co-authored-by: arii <342438+arii@users.noreply.github.com>
🤖 Gemini Review SkippedReview was skipped for the following reason: 🤖 Manual Trigger Quick Reference
|
- Removed `SPOTIFY_BRAND_COLOR` from `constants/spotify.ts` which was causing `knip` validation to fail after it was no longer used in `SpotifyControls.tsx`. Co-authored-by: arii <342438+arii@users.noreply.github.com>
🤖 Gemini Review SkippedReview was skipped for the following reason: 🤖 Manual Trigger Quick Reference
|
🤖 AI Technical AuditCode Review: Stability Fixes & CleanupThis PR effectively addresses the server-side crash in Critical Issues1. Broken Throttle Implementation (
When
Result: The volume command is likely sent on every slider move if the component re-renders (which happens often with sliders or polling), defeating the purpose of throttling. Fix: Use a Anti-AI-Slop Directives
File-by-File Analysis
Review automatically published via RepoAuditor. |
🤖 AI Technical AuditCode Review: PR #9447 - Fix Spotify Polling crash and cleanup UI slopThis PR addresses a critical server-side crash in the Spotify polling service and refactors volume control logic in the UI. While the crash fix and optimistic updates are valuable, there are issues regarding resource cleanup (throttling), dead code retention, and state mutation patterns. ANTI-AI-SLOP DIRECTIVES
File-by-File Analysis
|
- Update `throttledSendVolumeCommand` to use `.cancel()` on unmount. - Remove verbose slop comments in `services/spotifyPolling.ts`. - Ensure `jest.useRealTimers()` in `SpotifyControls.test.tsx` runs in `afterEach`. - Remove stale `VOLUME_SYNC_GRACE_PERIOD_MS` constant. Co-authored-by: arii <342438+arii@users.noreply.github.com>
🤖 Gemini Review SkippedReview was skipped for the following reason: 🤖 Manual Trigger Quick Reference
|
🤖 AI Technical AuditDeep Review: PR #9447This PR simplifies the Spotify volume synchronization logic and introduces optimistic updates for playback state. While the cleanup in
|
I have addressed all the feedback in your review. Specifically, I've updated |
- Use `useRef` and `useMemo` for `throttledSendVolumeCommand` in `SpotifyControls.tsx` to fix React dependency issues, and cancel the throttle on unmount. - Add `jest.useRealTimers()` inside a global `afterEach` block in `SpotifyControls.test.tsx` to improve test hygiene. - Remove the unused `VOLUME_SYNC_GRACE_PERIOD_MS` from `constants/spotify.ts` and `SpotifyDisplay.tsx`. - Strip away verbose comment slop from `services/spotifyPolling.ts`. Co-authored-by: arii <342438+arii@users.noreply.github.com>
🤖 Gemini Review SkippedReview was skipped for the following reason: 🤖 Manual Trigger Quick Reference
|
Description
Fixes a critical stability issue where accessing
this.state.playback.is_playingcould crash the server-side polling service if uninitialized. Also performs code cleanup in UI controls and tests according to recent review directives, such as reducing slop comments and extracting helper functions for test mock setups.Fixes #
Change Type: 🐛 Bug fix (non-breaking change fixing an issue)
Related Issues
Closes #
Original PR Body
Fixes a critical stability issue where accessing
this.state.playback.is_playingcould crash the server-side polling service if uninitialized. Also performs code cleanup in UI controls and tests according to recent review directives, such as reducing slop comments and extracting helper functions for test mock setups.PR created automatically by Jules for task 3337824891126205794 started by @arii