Skip to content
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

chore(frontend): add unoptimized flag to images #81

Closed
wants to merge 1 commit into from

Conversation

alcercu
Copy link
Collaborator

@alcercu alcercu commented Feb 11, 2025

Summary by CodeRabbit

  • Refactor
    • Adjusted the hero section image handling across multiple pages. Background images now load without automatic optimization, potentially affecting load performance and display quality while maintaining the overall design and functionality.

Copy link
Contributor

coderabbitai bot commented Feb 11, 2025

Walkthrough

This pull request updates multiple Hero components across the frontend by adding the unoptimized prop to the Next.js Image component. The change disables the default image optimization and applies uniformly across components in different directories. No public API or structural changes are introduced.

Changes

File(s) Change Summary
frontend/src/app/for-lawyers/components/Hero.tsx, frontend/src/app/home/components/Hero.tsx Added unoptimized prop to the Image component to disable Next.js image optimization.
frontend/src/components/(BrandAssets, Community, Cooperative, Earn, ForBuilders, PNKToken, ResearchDevelopment)/Hero.tsx Introduced the unoptimized property to the Image component in Hero components, modifying image rendering without affecting existing logic.

Possibly related PRs

Suggested reviewers

  • kemuru

Poem

In fields of code I hop with cheer,
For images now load without a fear,
Unoptimized and free to roam,
Each Hero shines like a bright chrome,
🥕 A rabbit's ode to change so dear!


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Feb 11, 2025

Deploy Preview for kleros-website-v2 ready!

Name Link
🔨 Latest commit c5b41a2
🔍 Latest deploy log https://app.netlify.com/sites/kleros-website-v2/deploys/67ab11cf8c5c6c000795e092
😎 Deploy Preview https://deploy-preview-81--kleros-website-v2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
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.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
frontend/src/components/BrandAssets/Hero.tsx (1)

30-37: 💡 Verification agent

🧩 Analysis chain

Verify performance impact of disabling image optimization.

The unoptimized prop disables Next.js's automatic image optimization. For background images, this might be intentional, but we should verify:

  1. The rationale behind disabling optimization
  2. Whether this impacts Core Web Vitals (LCP)

🌐 Web query:

What are the implications of using unoptimized prop in Next.js Image component?

💡 Result:

Using the unoptimized prop in Next.js Image component bypasses key optimization features with several implications:

Core Functionality Changes

  • Disables automatic compression/resizing: Images retain original file size and dimensions[3][10]
  • No format conversion: Modern formats like WebP/AVIF won't be generated[3][8]
  • Bypasses Vercel's CDN cache: Serves images directly from source without edge caching[3]

Performance Trade-offs

  • Increased bandwidth usage: Uncompressed images consume more data (e.g., 603kb vs optimized 80kb)[1]
  • Slower LCP metrics: Large images take longer to load critical content[2][5]
  • Potential layout shifts: Loses automatic CLS prevention features[4][6]

Appropriate Use Cases

Use unoptimized only when:

<Image 
  src="/logo.svg" 
  unoptimized 
  width={100}
  height={50}
  alt="SVG logo"
/>
  • Serving vector graphics (SVG)[3][9]
  • Animated images (GIF)[3][10]
  • Tiny assets <10KB (icons/thumbnails)[3]
  • Dynamic content requiring fresh updates[3]

Configuration Options

Set globally via next.config.js:

module.exports = {
  images: {
    unoptimized: true // Disables for all images
  }
}

This overrides individual component props[10]. Teams using external CDNs like ImageKit would configure this while setting up custom loaders[2].

Key Considerations

  1. SEO impact: Unoptimized images may hurt page speed rankings[2][5]
  2. Accessibility loss: Manual handling required for lazy loading/CLS prevention[4][6]
  3. Cost implications: External image services might charge more for origin traffic[3]

For most production use cases, keep unoptimized={false} (default) to leverage Next.js' automatic optimizations[1][4][8]. Reserve this prop only for special scenarios where optimization provides no tangible benefits[3][9].

Citations:


Performance impact of disabling optimization on this above-the-fold background image should be carefully considered.

Based on the gathered information, using the unoptimized prop means that the Next.js Image component will bypass automatic compression, resizing, and format conversion. For a full-screen, priority background image, this could lead to:

  • Increased bandwidth usage if the original image file is large.
  • Slower LCP (Largest Contentful Paint) metrics due to the image not being resized or compressed.
  • A loss of automatic optimizations that help prevent layout shifts (CLS) and improve SEO.

It’s important to verify that the background image file is either already optimized manually or small enough to mitigate these potential issues. If the intention is to use a fallback for images that don’t benefit from Next.js’ optimization (e.g., SVGs or very small assets), please ensure that these conditions are documented.

🧹 Nitpick comments (1)
frontend/src/components/ForBuilders/Hero.tsx (1)

30-37: Consider documenting the image optimization strategy.

The consistent use of unoptimized for hero background images across components suggests an intentional optimization strategy. Consider:

  1. Documenting this pattern in your frontend guidelines
  2. Creating a wrapper component like HeroBackground that encapsulates this behavior
  3. Adding comments explaining why background images are left unoptimized

This will help maintain consistency and clarify the optimization strategy for future developers.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 14d328e and c5b41a2.

📒 Files selected for processing (9)
  • frontend/src/app/for-lawyers/components/Hero.tsx (1 hunks)
  • frontend/src/app/home/components/Hero.tsx (1 hunks)
  • frontend/src/components/BrandAssets/Hero.tsx (1 hunks)
  • frontend/src/components/Community/hero.tsx (1 hunks)
  • frontend/src/components/Cooperative/hero.tsx (1 hunks)
  • frontend/src/components/Earn/Hero.tsx (1 hunks)
  • frontend/src/components/ForBuilders/Hero.tsx (1 hunks)
  • frontend/src/components/PNKToken/Hero.tsx (1 hunks)
  • frontend/src/components/ResearchDevelopment/Hero.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • frontend/src/components/Earn/Hero.tsx
  • frontend/src/components/Community/hero.tsx
  • frontend/src/app/for-lawyers/components/Hero.tsx
  • frontend/src/components/PNKToken/Hero.tsx
🔇 Additional comments (4)
frontend/src/components/Cooperative/hero.tsx (1)

41-48: LGTM - Maintains consistency with other Hero components.

The addition of the unoptimized prop is consistent with the pattern applied across other Hero components.

frontend/src/components/ResearchDevelopment/Hero.tsx (1)

47-54: LGTM - Consistent with the established pattern.

The addition of the unoptimized prop maintains consistency with other Hero components.

frontend/src/components/ForBuilders/Hero.tsx (1)

45-52: LGTM - Good selective application of optimization.

The unoptimized prop is correctly applied only to the background image while keeping the LinkArrow image optimized. This selective approach demonstrates good judgment in optimization strategy.

frontend/src/app/home/components/Hero.tsx (1)

52-59: Consider performance implications of disabling image optimization.

Adding the unoptimized prop disables Next.js automatic image optimization, which could impact performance, especially for background images that need to adapt to different viewport sizes.

Let's check the current Next.js documentation for image optimization best practices:

✅ Verification successful

🌐 Web query:

When should the unoptimized prop be used in Next.js Image component?

💡 Result:

The unoptimized prop in Next.js' Image component should be used in these key scenarios:

For specific image types

  • Animated images (GIF/APNG/WebP) where optimization would break animation[1][3]
  • SVG vector graphics since they scale losslessly[1][4]
  • Images <1KB where optimization provides negligible benefits[1][3]

When optimization isn't beneficial

  • Pre-optimized content from image CDNs like Imgix or Cloudinary[3][10]
  • Frequently changing images where caching causes stale content[3]
  • Testing/development environments to reduce build times[2]

Cost control measures

  • Reducing Vercel's Image Optimization usage costs by minimizing unique source images[2][3]
  • When using third-party CDNs that handle optimization separately[2][5]

Implementation methods

  1. Per-image basis:
<Image 
  src="/logo.svg" 
  unoptimized
  width={100}
  height={100}
  alt="Logo"
/>
  1. Global configuration in next.config.js:
module.exports = {
  images: {
    unoptimized: true
  }
}

Key considerations

  • Animated images are auto-detected but explicit unoptimized is recommended[1]
  • SVG requires either unoptimized or dangerouslyAllowSVG config[1][4]
  • Disabling optimization affects Core Web Vitals metrics - use only when necessary[8]
  • Combines with contentDispositionType for SVG security[1]

For most production sites, reserve unoptimized for special cases while letting Next.js handle optimization for standard JPEG/PNG/WebP images.[3][7]

Citations:


Performance Impact: Validate Use of unoptimized Flag

The current change correctly adds the unoptimized prop to the background image; however, please ensure that this usage is justified. Disabling Next.js image optimization can lead to larger image sizes and slower loads if the image isn’t already optimized or served by an external CDN. Review the scenarios from Next.js documentation and confirm that the background image meets one of the recommended conditions (such as being pre-optimized or belonging to a specific image type).

  • File: frontend/src/app/home/components/Hero.tsx (Lines 52–59)
  • Action: Assess if the background image is pre-optimized or if an external service is used to optimize it. If not, consider alternative approaches that leverage Next.js image optimization.

@alcercu alcercu closed this Feb 11, 2025
@alcercu alcercu deleted the chore(frontend)/test-unoptimized-images branch February 11, 2025 16:34
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.

1 participant