Skip to content

fix(watch): bypass optimizer for local thumbnails#9242

Open
lumberman wants to merge 2 commits into
mainfrom
05-21-OA-fix-watch-local-thumbnail-unoptimized
Open

fix(watch): bypass optimizer for local thumbnails#9242
lumberman wants to merge 2 commits into
mainfrom
05-21-OA-fix-watch-local-thumbnail-unoptimized

Conversation

@lumberman
Copy link
Copy Markdown
Contributor

@lumberman lumberman commented May 21, 2026

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/thumbnail response 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=false
  • Helium smoke was attempted against the local watch page, but local rendering was blocked by unavailable watch app environment/config (NEXT_PUBLIC_ALGOLIA_APP_ID / Algolia API key).

Compound Engineering
GPT_5

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced video thumbnail handling to improve rendering performance for locally-sourced thumbnail images.
    • Updated the video card component to properly detect and process local thumbnail sources.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Walkthrough

VideoCard component now detects local thumbnail URLs and disables Next.js image optimization for them via the unoptimized prop. The test mock for next/image is expanded to track this prop, and test coverage verifies the behavior for both local and default thumbnails.

Changes

Local Thumbnail Unoptimization

Layer / File(s) Summary
Local thumbnail unoptimization detection
apps/watch/src/components/VideoCard/VideoCard.tsx
VideoCard derives an isLocalThumbnailUrl flag when thumbnailUrl starts with /watch/images/thumbnails/ and passes unoptimized={isLocalThumbnailUrl} to the next/image component to skip optimization for local paths.
Test infrastructure and verification
apps/watch/setupTests.tsx, apps/watch/src/components/VideoCard/VideoCard.spec.tsx
The next/image mock now accepts unoptimized and sets data-unoptimized="true" for test assertion. New test case verifies local thumbnail overrides render with unoptimized flag set; existing test tightened to confirm the flag is absent for default video-provided thumbnails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • csiyang
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(watch): bypass optimizer for local thumbnails' directly and specifically describes the main change—disabling Next.js image optimization for local thumbnail paths in the watch app.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 05-21-OA-fix-watch-local-thumbnail-unoptimized

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 21, 2026

View your CI Pipeline Execution ↗ for commit a4926b0

Command Status Duration Result
nx run watch-e2e:e2e ✅ Succeeded 17s View ↗
nx run-many --target=vercel-alias --projects=watch ✅ Succeeded 1s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 4s View ↗
nx run-many --target=deploy --projects=watch ✅ Succeeded 38s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-22 01:17:59 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 21, 2026

View your CI Pipeline Execution ↗ for commit e9bc49e

Command Status Duration Result
nx run watch-e2e:e2e ✅ Succeeded 18s View ↗
nx run-many --target=vercel-alias --projects=watch ✅ Succeeded 1s View ↗
nx run-many --target=upload-sourcemaps --projec... ✅ Succeeded 5s View ↗
nx run-many --target=deploy --projects=watch ✅ Succeeded 1m 15s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-21 18:55:38 UTC

@github-actions github-actions Bot temporarily deployed to Preview - watch May 21, 2026 18:50 Inactive
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 21, 2026

The latest updates on your projects.

Name Status Preview Updated (UTC)
watch ✅ Ready watch preview Fri May 22 13:15:48 NZST 2026

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/watch/setupTests.tsx (1)

13-19: ⚡ Quick win

Type the mocked next/image props 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

📥 Commits

Reviewing files that changed from the base of the PR and between 64b1ad2 and e9bc49e.

📒 Files selected for processing (3)
  • apps/watch/setupTests.tsx
  • apps/watch/src/components/VideoCard/VideoCard.spec.tsx
  • apps/watch/src/components/VideoCard/VideoCard.tsx

@tataihono tataihono self-assigned this May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants