-
Notifications
You must be signed in to change notification settings - Fork 683
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
Generate optimized Image URLs using configuration from GraphQL #1267
Conversation
- Update tests to reflect functionality change with absolute URLs
This pull request is automatically deployed with Now. Latest deployment for this branch: https://venia-git-feature-graphql-media-urls.magento-research1.now.sh |
|
||
if (type) { | ||
if (mediaBases.has(type)) { | ||
// If URL is relative and has a supported type, prepend media base onto path | ||
if (!isAbsolute && mediaBases.has(type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made the decision to remove functionality that tries to inject media bases into absolute URLs. Logically, I couldn't think of a use case where we receive an absolute URL that doesn't already have the media base in it. If I'm missing something, let me know, and I will re-implement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -30,18 +30,12 @@ test('prepends media path for product images', () => { | |||
expect(makeUrl(relativePath, { type: 'image-product' })).toBe( | |||
`${productBase}${relativePath}?${defaultParams}` | |||
); | |||
expect(makeUrl(absoluteUrls[2], { type: 'image-product' })).toBe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test changes all related to removed functionality. See https://github.com/magento-research/pwa-studio/pull/1267/files#r287155267
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can drop some conditionals 👍
|
||
if (type) { | ||
if (mediaBases.has(type)) { | ||
// If URL is relative and has a supported type, prepend media base onto path | ||
if (!isAbsolute && mediaBases.has(type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# but if your Magento instance does something different, they're configurable | ||
# here. | ||
# MAGENTO_BACKEND_MEDIA_PATH_PRODUCT="/media/catalog/product" | ||
# MAGENTO_BACKEND_MEDIA_PATH_CATEGORY="/media/catalog/category" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we dropping support for these entirely? If so I think that means this has to be a major version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and yes!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue this isn't a major, and is fully backwards compatible for developers that were previously using them. To resolve the docroot bug, you would prefix these values with /pub
, and update the proxy pattern in venia-upward.yml
to '^/(graphql|rest|pub/media)(/|$)'
.
An upgrade makes them obsolete, but nothing breaks. I could see it going both ways, if upward config or environment variables are considered API (ie. you used them in your custom app code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If nothing breaks I'm okay with that then. I think the next version is already going to be a major so it may be moot anyway.
Code looks good, running verification steps now |
@tjwiebell and I are going to pair on the verification steps |
Description
Made changes necessary to source media URL from GraphQL, and made it so it was backwards compatible with the image optimization middleware that would not have access to this configuration value. This should mean backing instances that aren't using
/pub
as their document root, not require zero additional steps to get Venia up and running. This additionally supports media URLs that are completely external of the Magento backing system, which can be more common with larger instances (eg. an Amazon S3 bucket, or a CDN).Related Issue
Closes #567
Verification Steps
onboard image opt w/
/pub
as document rootX-Image-Compressed-By: PWA Studio Staging Server
header and that they are optimizedonboard image opt w/
/
as document root/
and document root/pub
in all image requests now)backend image opt w/
/pub
as document rootIMAGE_OPTIMIZING_ORIGIN=backend
, and spin up VeniaX-Image-Compressed-By: PWA Studio Staging Server
header and that they are optimized by Fastly instead (should be webp, some Fastly headers)How Have YOU Tested this?
Ran manual tests above and jest
Screenshots / Screen Captures (if appropriate):
Proposed Labels for Change Type/Package
Checklist: