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

Derive image mime type from srcset #9751

Merged
merged 4 commits into from
Dec 16, 2021
Merged

Derive image mime type from srcset #9751

merged 4 commits into from
Dec 16, 2021

Conversation

amoore108
Copy link
Contributor

@amoore108 amoore108 commented Dec 16, 2021

Part of #9628

Overall change:
Adds logic to derived the mime-type of image srcsets. This allows older browsers to know what the image format of the srcset should be if they can't derive it from the server response

Code changes:

  • Updates the createSrcsets function to return mime-types for the primary and fallback srcset values. These get passed through to the psammead-image component and get set on the <source /> elements

Enabled by: BBC-archive/psammead#4608


  • I have assigned myself to this PR and the corresponding issues
  • I have added the cross-team label to this PR if it requires visibility across World Service teams
  • I have assigned this PR to the Simorgh project
  • (BBC contributors only) This PR follows the repository use guidelines

Testing:

  • Automated (jest and/or cypress) tests added (for new features) or updated (for existing features)
  • If necessary, I have run the local E2E non-smoke tests relevant to my changes (CYPRESS_APP_ENV=local CYPRESS_SMOKE=false yarn test:e2e:interactive)
  • This PR requires manual testing

@amoore108 amoore108 self-assigned this Dec 16, 2021
@amoore108 amoore108 added cross-team For visibility for both World Service teams (Engage & Media) performance labels Dec 16, 2021
@amoore108 amoore108 changed the title [DNM] Derive image mime type Derive image mime type from srcset Dec 16, 2021
export const getMimeType = srcset => {
if (!srcset) return null;

const [firstSrcset] = srcset?.split(',');
Copy link
Contributor

@ryanmccombe ryanmccombe Dec 16, 2021

Choose a reason for hiding this comment

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

I believe the ?. is in the wrong place here? srcset is always defined (because of line 6).

I think the only scenario this function can throw an exception is that if srcset is not a string - in which case split would not be defined

Although updating line 6 to catch that is probably cleaner than optional chaining

Copy link
Contributor

@ryanmccombe ryanmccombe left a comment

Choose a reason for hiding this comment

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

👍

@amoore108 amoore108 merged commit 32a5c3e into latest Dec 16, 2021
@amoore108 amoore108 deleted the derive-image-mime-type branch December 16, 2021 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cross-team For visibility for both World Service teams (Engage & Media) performance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants