fix(watch): bypass optimizer for local thumbnails#9242
Conversation
WalkthroughVideoCard component now detects local thumbnail URLs and disables Next.js image optimization for them via the ChangesLocal Thumbnail Unoptimization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
View your CI Pipeline Execution ↗ for commit a4926b0
☁️ Nx Cloud last updated this comment at |
|
View your CI Pipeline Execution ↗ for commit e9bc49e
☁️ Nx Cloud last updated this comment at |
|
The latest updates on your projects.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/watch/setupTests.tsx (1)
13-19: ⚡ Quick winType the mocked
next/imageprops explicitly.Line 13 introduces untyped destructured props (
src,alt,unoptimized), which weakens test type-safety.Proposed fix
import '`@testing-library/jest-dom`' import 'isomorphic-fetch' import { configure } from '`@testing-library/react`' +import type { ImageProps } from 'next/image' import { server } from './test/mswServer' import './test/i18n' @@ jest.mock('next/image', () => ({ __esModule: true, // eslint-disable-next-line `@next/next/no-img-element` - default: ({ src, alt, unoptimized }) => ( + default: ({ src, alt, unoptimized }: ImageProps) => ( <img - src={src} + src={typeof src === 'string' ? src : src.src} alt={alt} data-unoptimized={unoptimized === true ? 'true' : undefined} /> ) }))As per coding guidelines, “All components and functions must be fully typed with TypeScript.”
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@apps/watch/setupTests.tsx` around lines 13 - 19, The default mock for next/image currently uses untyped destructured props; add an explicit TypeScript type for the parameter of the default arrow function (e.g., replace "({ src, alt, unoptimized }) =>" with a typed signature like "(props: { src: string; alt?: string; unoptimized?: boolean }) =>" or declare an interface (e.g., ImageProps) and use it, then destructure props inside the function; this ensures the mocked component (the default arrow function) has fully typed props and preserves optionality for alt and unoptimized.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@apps/watch/setupTests.tsx`:
- Around line 13-19: The default mock for next/image currently uses untyped
destructured props; add an explicit TypeScript type for the parameter of the
default arrow function (e.g., replace "({ src, alt, unoptimized }) =>" with a
typed signature like "(props: { src: string; alt?: string; unoptimized?: boolean
}) =>" or declare an interface (e.g., ImageProps) and use it, then destructure
props inside the function; this ensures the mocked component (the default arrow
function) has fully typed props and preserves optionality for alt and
unoptimized.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 8dfdbf09-d41f-45dd-92f3-aaafbd59b2ce
📒 Files selected for processing (3)
apps/watch/setupTests.tsxapps/watch/src/components/VideoCard/VideoCard.spec.tsxapps/watch/src/components/VideoCard/VideoCard.tsx
Summary
Experimental watch cards can now load local thumbnail override files directly instead of sending cache-busted
/watch/images/thumbnails/...URLs through Next image optimization. Remote thumbnail URLs still use the optimized image path.The change keeps the existing
/watch/api/thumbnailresponse shape intact, including the?v=cache buster, and scopes the optimizer bypass to local thumbnail override paths only.Testing
pnpm exec jest --config apps/watch/jest.config.ts apps/watch/src/components/VideoCard/VideoCard.spec.tsx --runInBand --coverage=falseNEXT_PUBLIC_ALGOLIA_APP_ID/ Algolia API key).Summary by CodeRabbit