Skip to content

Remove assertNoComplexSizes from NgOptimizedImage #59495

Description

@jakubsobel

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

Currently you can't use pixel values in sizes in NgOptimizedImage.

Code like that:
sizes="(max-width: 540px) 100vw, (max-width: 960px) 50vw, 370px"
will cause NG02952 exception in dev mode, because of assertNoComplexSizes function in NgOptimizedImage directive code. Yet, in production it will produce proper srcset and will render just fine.

I've read NgOptimizedImage source, and I can't find any logic there that can explain why that assertion is necessary.
I have sizes like that (responsive for mobile/tablet, fixed for desktop) in my production code for regular img elements. That limitation of sizes stops me from easily switching to NgOptimizedImage.

Proposed solution

Remove assertNoComplexSizes assertion from NgOptimizedImage source.

Alternatives considered

Add option to disable assertNoComplexSizes assertion conditionally somehow in dev mode.

Activity

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

    area: commonIssues related to APIs in the @angular/common packagecommon: image directiveopen for contributionsAn issue that is suitable for a community contributor (based on its complexity/scope).

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions