Skip to content

NgOptimizedImage: unclear behavior when ngSrcset is used with default image loader #48655

Closed

Description

@Timbo1979

Which @angular/* package(s) are the source of the bug?

common

Is this a regression?

Yes

Description

In my Angular 15.x project I'm using NgOptimizedImage with ngSrc and ngSrcset but getting incorrect result according to the documentation.

When I enter:

<img ngSrc="hello.jpg" ngSrcset="100w, 200w" />

Documentation says I should get:
<img src="path/hello.jpg" srcset="path/hello.jpg?w=100 100w, path/hello.jpg?w=200 200w" />

Instead I get:
<img src="path/hello.jpg" srcset="path/hello.jpg 100w, path/hello.jpg 200w" />

So the same image is returned for all viewports.

Please provide a link to a minimal reproduction of the bug

https://stackblitz.com/edit/angular-bf98bj?file=src%2Fapp%2Fapp.component.html,src%2Fapp%2Fapp.module.ts

Please provide the exception or error you saw

No response

Please provide the environment you discovered this bug in (run ng version)

Angular CLI: 15.0.1
Node: 16.15.1
Package Manager: npm 9.1.2
OS: win32 x64

Angular: 15.0.1
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1500.1
@angular-devkit/build-angular   15.0.1
@angular-devkit/core            15.0.1
@angular-devkit/schematics      15.0.1
@schematics/angular             15.0.1
rxjs                            7.5.7
typescript                      4.8.4

Anything else?

No response

Activity

  1. jnizet commented on Jan 6, 2023

    @jnizet
    Contributor

    Hi @Timbo1979

    As far as I understand, the URL that is generated depends on the ImageLoader that you have provided. If you haven't provided any, then the default one will just return the path of the image, regardless of the requested width, because that's what allows loading a static image.

  2. AndrewKushnir commented on Jan 9, 2023

    @AndrewKushnir
    Contributor

    @Timbo1979 as @jnizet mentioned above, there is no image loader configured (see docs), thus there were no image URL transformation performed.

    I'm leaving this ticket open to see if we should add a warning when the ngSrcset is present and a default image loader is used.

  3. added
    area: common
    on Jan 9, 2023
  4. modified the milestone: needsTriage on Jan 9, 2023
  5. changed the title [-]Angular 15 NgOptimizedImage issue[/-] [+]NgOptimizedImage: unclear behavior when ngSrcset is used with default image loader[/+] on Jan 9, 2023
  6. added
    open for contributions
    on Jan 10, 2023
  7. AndrewKushnir commented on Jan 10, 2023

    @AndrewKushnir
    Contributor

    We've discussed this topic with the team and we'd like to add a logic to output a warning in case the ngSrcset is present and no loaders are configured (i.e. only the default one is present). The warning should be helpful for cases like the one described in this ticket.

    I'm adding the "help wanted" label to see if there is an interest from community members to contribute a PR with this change.

    Thank you.

  8. added
    P3
    on Jan 10, 2023
  9. modified the milestones: needsTriage, Backlog on Jan 10, 2023
  10. atcastle commented on Mar 4, 2024

    @atcastle
    Contributor

    @AndrewKushnir Let's just close this issue. It's fixed by #48804

  11. angular-automatic-lock-bot commented on Apr 4, 2024

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  12. locked and limited conversation to collaborators on Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3area: commoncommon: image directiveopen for contributions

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions