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

264-fix: load images for smal window #333

Closed

Conversation

ya6
Copy link
Collaborator

@ya6 ya6 commented Jun 22, 2024

What type of PR is this? (select all that apply)

  • πŸ• Feature
  • πŸ› Bug Fix
  • 🚧 Breaking Change
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ“ Documentation Update

Description

In my opinion the approach works like a "silver bullet" with the presence of this error

After trying several approaches, in the latest version of the files I suggest:

  • remove svg files when generating srcSet
  • and if we replace some of the files with svg and change those pictures whose width, for example, 300 pixels, to more than 768, the size of the webp file will practically not increase, but the scrSet will be fully created and the error will go away)

Related Tickets & Documents

Screenshots, Recordings

Added/updated tests?

  • πŸ‘Œ Yes
  • πŸ™…β€β™‚οΈ No, because they aren't needed
  • πŸ™‹β€β™‚οΈ No, because I need help

Summary by CodeRabbit

  • New Features

    • Enhanced image component with improved handling of srcSet and sizes attributes for better image loading capabilities.
    • Added support for checking if an image URL is an SVG format, providing more flexibility in image processing.
  • Improvements

    • Converted various image utility functions to named exports for better maintainability and readability.

Copy link
Member

@Quiddlee Quiddlee Jun 23, 2024

Choose a reason for hiding this comment

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

This will not fix the errors.

From the image optimization doc
image

There is a clear statement that if an image is already small, the 2 smaller sizes not gonna be created.

Therefore when the browser loading the image that is missing it throws 404 error and Image fallbacks to basic src instead of srcSet

image

Because of this behavior, errors occurs.

We have 3 variants on how to fix this:

  1. We can generate two more images with different names but the same size as the original. For example, if the existing logo is named "RS logo" and is 90x90 pixels, we would generate two more copies named "image-name-768" and "image-name-425." These additional images would essentially be placeholders.

  2. This option is more complex. It involves checking all the created images, parsing the build code, and then modifying the srcSet attribute for each image. The modification would be to remove any references to responsive image sizes that are missing.

  3. We can ignore the errors, or somehow clear the console after the image performed fallback

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This will not fix the errors.

From the image optimization doc image

There is a clear statement that if an image is already small, the 2 smaller sizes not gonna be created.

Therefore when the browser loading the image that is missing it throws 404 error and Image fallbacks to basic src instead of srcSet

image

Because of this behavior, errors occurs.

We have 3 variants on how to fix this:

  1. We can generate two more images with different names but the same size as the original. For example, if the existing logo is named "RS logo" and is 90x90 pixels, we would generate two more copies named "image-name-768" and "image-name-425." These additional images would essentially be placeholders.
  2. This option is more complex. It involves checking all the created images, parsing the build code, and then modifying the srcSet attribute for each image. The modification would be to remove any references to responsive image sizes that are missing.
  3. We can ignore the errors, or somehow clear the console after the image performed fallback

I agree with the proposed possible solutions.
If generate a srcSet for them, about 100 more files are added and the size of the application grows
The second option to increase the complexity of an already complex solution will not be optimal
There is another solution to replace the files with svg, but I still don’t think this is the optimal solution.

Copy link
Contributor

coderabbitai bot commented Jun 24, 2024

Walkthrough

The recent updates primarily involve enhancements to the Image component and its utility functions to handle image formats better and ensure robust state initialization. Key adjustments include the introduction of a new checkIfSvg utility, changes to the import statements, and additional logic for state handling based on environment variables and image format checks.

Changes

File Change Summary
src/shared/ui/image/image.tsx Updated imports, added checkIfSvg utility, and modified srcSet and sizes state initialization.
src/shared/ui/image/utils/checkIfSvg.ts Introduced a new function to check if an image URL ends with .svg.
src/shared/ui/image/utils/convertToWebp.ts Converted convertToWebp from a default export to a named exported constant.
src/shared/ui/image/utils/generateSizes.ts Modified generateSizes to be a named exported function.
src/shared/ui/image/utils/generateSrcSet.ts Changed generateSrcSet from a default export to a named export.

Sequence Diagrams

Sequence diagrams are not applicable for these changes as they mainly include small adjustments and refactoring rather than new features or complex control flows.

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Fix the error in console when browser window is small (#264) βœ…

Poem

A code so sleek in image fair,
To thwart the errors hiding there,
With checks for SVGs in sight,
And states that initialize just right,
For bugs we bid a swift goodbye,
As windows small, our code will fly! πŸ°πŸš€


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?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

github-actions bot commented Jun 26, 2024

Qodana for JS

It seems all right πŸ‘Œ

No new problems were found according to the checks applied

πŸ’‘ Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Detected 80 dependencies

Third-party software list

This page lists the third-party software dependencies used in project

Dependency Version Licenses
@next/env 14.2.3 MIT
@next/swc-linux-x64-gnu 14.2.3 MIT
@next/swc-linux-x64-musl 14.2.3 MIT
@playwright/test 1.44.1 Apache-2.0
@remix-run/router 1.16.1 MIT
@swc/counter 0.1.3 Apache-2.0
@swc/helpers 0.5.5 Apache-2.0
anymatch 3.1.3 ISC
binary-extensions 2.3.0 MIT
braces 3.0.3 MIT
brcast 3.0.2 MIT
busboy 1.6.0 MIT
caniuse-lite 1.0.30001616 CC-BY-4.0
chokidar 3.6.0 MIT
classnames 2.5.1 MIT
client-only 0.0.1 MIT
css-vendor 0.3.8 MIT
dayjs 1.11.11 MIT
fill-range 7.1.1 MIT
glob-parent 5.1.2 ISC
graceful-fs 4.2.11 ISC
hoist-non-react-statics 2.5.5 BSD-3-Clause
hyphenate-style-name 1.0.4 BSD-3-Clause
immutable 4.3.5 MIT
is-binary-path 2.1.0 MIT
is-function 1.0.2 MIT
is-glob 4.0.3 MIT
is-in-browser 1.1.3 MIT
is-number 7.0.0 MIT
is-plain-object 2.0.4 MIT
isobject 3.0.1 MIT
js-tokens 4.0.0 MIT
jss-camel-case 6.1.0 MIT
jss-compose 5.0.0 MIT
jss-default-unit 8.0.2 MIT
jss-expand 5.3.0 MIT
jss-extend 6.2.0 MIT
jss-global 3.0.0 MIT
jss-nested 6.0.1 MIT
jss-preset-default 4.5.0 MIT
jss-props-sort 6.0.0 MIT
jss-template 1.0.1 MIT
jss-vendor-prefixer 7.0.0 MIT
jss 9.8.7 MIT
loose-envify 1.4.0 MIT
nanoid 3.3.7 MIT
next 14.2.3 MIT
nextjs-toploader 1.6.12 MIT
normalize-path 3.0.0 MIT
nprogress 0.2.0 MIT
object-assign 4.1.1 MIT
picocolors 1.0.1 ISC
picomatch 2.3.1 MIT
playwright-core 1.44.1 Apache-2.0
playwright 1.44.1 Apache-2.0
postcss 8.4.31 MIT
prop-types 15.8.1 MIT
react-dom 16.14.0 MIT
react-dom 18.3.1 MIT
react-double-marquee 1.1.0 MIT
react-easy-swipe 0.0.21 MIT
react-is 16.13.1 MIT
react-json-pretty 2.2.0 MIT
react-jss 8.6.1 MIT
react-responsive-carousel 3.2.23 MIT
react-router-dom 6.23.1 MIT
react-router 6.23.1 MIT
react 16.14.0 MIT
react 18.3.1 MIT
readdirp 3.6.0 MIT
sass 1.77.4 Apache-2.0
scheduler 0.19.1 MIT
scheduler 0.23.2 MIT
source-map-js 1.2.0 BSD-3-Clause
streamsearch 1.1.0 MIT
styled-jsx 5.1.1 MIT
theming 1.3.0 MIT
to-regex-range 5.0.1 MIT
tslib 2.6.2 0BSD
warning 3.0.0 BSD-3-Clause
Contact Qodana team

Contact us at qodana-support@jetbrains.com

@ya6
Copy link
Collaborator Author

ya6 commented Jul 3, 2024

In my opinion the approach works like a "silver bullet" with the presence of this error
After trying several approaches, in the latest version of the files I suggest:

  • remove svg files when generating srcSet
  • and if we replace some of the files with svg and change those pictures whose width, for example, 300 pixels, to more than 768, the size of the webp file will practically not increase, but the scrSet will be fully created and the error will go away)

Copy link

github-actions bot commented Jul 3, 2024

Lighthouse Report:

  • Performance: 79 / 100
  • Accessibility: 88 / 100
  • Best Practices: 93 / 100
  • SEO: 91 / 100

View detailed report

Copy link

github-actions bot commented Jul 4, 2024

Qodana for JS

It seems all right πŸ‘Œ

No new problems were found according to the checks applied

πŸ’‘ Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Detected 82 dependencies

Third-party software list

This page lists the third-party software dependencies used in project

Dependency Version Licenses
@next/env 14.2.3 MIT
@next/swc-linux-x64-gnu 14.2.3 MIT
@next/swc-linux-x64-musl 14.2.3 MIT
@playwright/test 1.45.0 Apache-2.0
@remix-run/router 1.17.0 MIT
@swc/counter 0.1.3 Apache-2.0
@swc/helpers 0.5.5 Apache-2.0
anymatch 3.1.3 ISC
binary-extensions 2.3.0 MIT
braces 3.0.3 MIT
brcast 3.0.2 MIT
busboy 1.6.0 MIT
caniuse-lite 1.0.30001616 CC-BY-4.0
chokidar 3.6.0 MIT
class-variance-authority 0.7.0 Apache-2.0
classnames 2.5.1 MIT
client-only 0.0.1 MIT
clsx 2.0.0 MIT
css-vendor 0.3.8 MIT
dayjs 1.11.11 MIT
fill-range 7.1.1 MIT
glob-parent 5.1.2 ISC
graceful-fs 4.2.11 ISC
hoist-non-react-statics 2.5.5 BSD-3-Clause
hyphenate-style-name 1.0.4 BSD-3-Clause
immutable 4.3.5 MIT
is-binary-path 2.1.0 MIT
is-function 1.0.2 MIT
is-glob 4.0.3 MIT
is-in-browser 1.1.3 MIT
is-number 7.0.0 MIT
is-plain-object 2.0.4 MIT
isobject 3.0.1 MIT
js-tokens 4.0.0 MIT
jss-camel-case 6.1.0 MIT
jss-compose 5.0.0 MIT
jss-default-unit 8.0.2 MIT
jss-expand 5.3.0 MIT
jss-extend 6.2.0 MIT
jss-global 3.0.0 MIT
jss-nested 6.0.1 MIT
jss-preset-default 4.5.0 MIT
jss-props-sort 6.0.0 MIT
jss-template 1.0.1 MIT
jss-vendor-prefixer 7.0.0 MIT
jss 9.8.7 MIT
loose-envify 1.4.0 MIT
nanoid 3.3.7 MIT
next 14.2.3 MIT
nextjs-toploader 1.6.12 MIT
normalize-path 3.0.0 MIT
nprogress 0.2.0 MIT
object-assign 4.1.1 MIT
picocolors 1.0.1 ISC
picomatch 2.3.1 MIT
playwright-core 1.45.0 Apache-2.0
playwright 1.45.0 Apache-2.0
postcss 8.4.31 MIT
prop-types 15.8.1 MIT
react-dom 16.14.0 MIT
react-dom 18.3.1 MIT
react-double-marquee 1.1.0 MIT
react-easy-swipe 0.0.21 MIT
react-is 16.13.1 MIT
react-json-pretty 2.2.0 MIT
react-jss 8.6.1 MIT
react-responsive-carousel 3.2.23 MIT
react-router-dom 6.24.0 MIT
react-router 6.24.0 MIT
react 16.14.0 MIT
react 18.3.1 MIT
readdirp 3.6.0 MIT
sass 1.77.6 Apache-2.0
scheduler 0.19.1 MIT
scheduler 0.23.2 MIT
source-map-js 1.2.0 BSD-3-Clause
streamsearch 1.1.0 MIT
styled-jsx 5.1.1 MIT
theming 1.3.0 MIT
to-regex-range 5.0.1 MIT
tslib 2.6.2 0BSD
warning 3.0.0 BSD-3-Clause
Contact Qodana team

Contact us at qodana-support@jetbrains.com

Copy link

github-actions bot commented Jul 4, 2024

Lighthouse Report:

  • Performance: 85 / 100
  • Accessibility: 88 / 100
  • Best Practices: 93 / 100
  • SEO: 91 / 100

View detailed report

Copy link

github-actions bot commented Jul 4, 2024

Lighthouse Report:

  • Performance: 76 / 100
  • Accessibility: 88 / 100
  • Best Practices: 93 / 100
  • SEO: 91 / 100

View detailed report

@ansivgit ansivgit marked this pull request as ready for review July 5, 2024 11:49
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 25df77f and d6453f7.

Files selected for processing (5)
  • src/shared/ui/image/image.tsx (1 hunks)
  • src/shared/ui/image/utils/checkIfSvg.ts (1 hunks)
  • src/shared/ui/image/utils/convertToWebp.ts (2 hunks)
  • src/shared/ui/image/utils/generateSizes.ts (1 hunks)
  • src/shared/ui/image/utils/generateSrcSet.ts (1 hunks)
Files skipped from review due to trivial changes (2)
  • src/shared/ui/image/utils/checkIfSvg.ts
  • src/shared/ui/image/utils/convertToWebp.ts
Additional comments not posted (5)
src/shared/ui/image/utils/generateSizes.ts (1)

7-7: LGTM!

The change to a named export for generateSizes is appropriate.

src/shared/ui/image/utils/generateSrcSet.ts (1)

8-8: LGTM!

The change to a named export for generateSrcSet is appropriate.

src/shared/ui/image/image.tsx (3)

5-8: LGTM!

The updated import statements appropriately include the checkIfSvg function and update other utilities to named exports.


12-13: LGTM!

The addition of the checkIfSvg function ensures that SVG files are correctly identified.


14-15: Conditional Initialization of States

The conditional initialization of srcSet and sizes based on the IS_DEV flag and checkIfSvg ensures that SVG files are handled appropriately. This change is logical and aligns with the bug fix objectives.

Copy link

github-actions bot commented Jul 5, 2024

Lighthouse Report:

  • Performance: 94 / 100
  • Accessibility: 88 / 100
  • Best Practices: 93 / 100
  • SEO: 91 / 100

View detailed report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix unknown error when the browser window is small
4 participants