-
Notifications
You must be signed in to change notification settings - Fork 325
Generate a default srcset for an image returned by the Shopify CDN #1330
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 a default srcset for an image returned by the Shopify CDN #1330
Conversation
|
Getting some alignment on things and then I'll provide a full code review. Thanks for your patience! |
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.
Thanks! It would be great if you could also add some tests in Image.test.tsx around this feature as well.
| scale?: 2 | 3; | ||
| width?: HtmlImageProps['width'] | ImageType['width']; | ||
| height?: HtmlImageProps['height'] | ImageType['height']; | ||
| widths?: (HtmlImageProps['width'] | ImageType['width'])[]; |
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.
ShopifyLoaderOptions is specifically for the object that gets passed to loader. In this case, I don't think we're going to pass widths to loader, so widths should probably just be its own top-level prop to Image.
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.
In this case, it may be worth actually just enforcing that they're of type number to make things easier for ourselves, instead of string | number. But I could be persuaded either way on this one.
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.
ShopifyLoaderOptionsis specifically for the object that gets passed toloader. In this case, I don't think we're going to passwidthstoloader, sowidthsshould probably just be its own top-level prop toImage.
The widths prop is now a top-level prop of Image
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.
In this case, it may be worth actually just enforcing that they're of type
numberto make things easier for ourselves, instead ofstring | number. But I could be persuaded either way on this one.
I think string representation of numbers should still be allowed since it follows the HMTL attributes types. The check handles both cases
| return setSizes | ||
| .map( | ||
| (size) => | ||
| `${addImageSizeParametersToUrl({ |
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.
This will result in different URLs for src and srcset if someone were to provide their own loader. So in this case, I think you want to remove addImageSizeParametersToUrl and instead take in the loader prop, and call loader() here instead. If that makes sense?
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.
This will result in different URLs for
srcandsrcsetif someone were to provide their ownloader. So in this case, I think you want to removeaddImageSizeParametersToUrland instead take in theloaderprop, and callloader()here instead. If that makes sense?
srcsets are now generated with a loader if one is provided. otherwise, it defaults to using addImageSizeParametersToUrl
| widths, | ||
| }: ShopifyLoaderParams) { | ||
| const hasCustomWidths = widths && Array.isArray(widths); | ||
| if (hasCustomWidths && widths.some((size) => isNaN(size as number))) |
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 love this check. 👍
| if ( | ||
| !hasCustomWidths && | ||
| width && | ||
| width < IMG_SRC_SET_SIZES[IMG_SRC_SET_SIZES.length - 1] |
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.
Is this check to make it so that there isn't a srcset option that has a width wider than the set width of the Image? Would it work the same if you removed this from the if statement and still filtered out the srcset on the line below?
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.
Is this check to make it so that there isn't a
srcsetoption that has a width wider than the setwidthof the Image? Would it work the same if you removed this from theifstatement and still filtered out thesrcseton the line below?
Yes, that is correct, srcsets are kept within the max image width to prevent distortion and poor quality images.
It would work the same without the if check, but I opted to check because the filter method returns a new array, and I wanted to avoid using extra memory if it's not needed. This optimization is minor. The computation and memory cost is negligible. PLP or pages with multiple images would benefit from this check. I can be convinced to remove it.
| }); | ||
| } | ||
|
|
||
| const finalSrcset = |
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.
We should probably do something similar to this for the ExternalImage component as well. We'd probably need to check for if there's a loader prop or not, too.
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.
We should probably do something similar to this for the
ExternalImagecomponent as well. We'd probably need to check for if there's aloaderprop or not, too.
It might be complicated for external images since we can't know how their CDN manages search parameters. We can explore this or have a curated list of CDN that we can support.
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.
Sorry, I was trying to say that on ExternalImage we should also do something like
const finalSrcset = rest.srcSet ?? (loader && widths)? widths.map(width => loader(...)) : nullif that makes sense?
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.
There is now a srcset generated for ExternalImage that has a loader and widths prop.
/** External images */
let finalSrcset = rest.srcSet ?? undefined;
if (!finalSrcset && loader && widths) {
// Height is a requirement in the LoaderProps, so to keep the aspect ratio, we must determine the height based on the default values
const heightToWidthRatio =
parseInt(height as string) / parseInt(width as string);
finalSrcset = widths
?.map((width) => parseInt(width as string, 10))
?.map(
(width) =>
`${loader({
...loaderOptions,
src,
width,
height: Math.floor(width * heightToWidthRatio),
})} ${width}w`
)
.join(', ');
}
/* eslint-disable hydrogen/prefer-image-component */
return (
<img
{...rest}
src={finalSrc}
width={width}
height={height}
alt={alt ?? ''}
loading={loading ?? 'lazy'}
srcSet={finalSrcset}
/>
);
docs/components/primitive/image.md
Outdated
| | `height` | A string of the pixel height (for example, `100px`) or `original` for the original height of the image. | | ||
| | `crop` | Valid values: `top`, `bottom`, `left`, `right`, or `center`. | | ||
| | `scale` | Valid values: 2 or 3. | | ||
| | `widths` | An array of pixel widths to overwrite the default generated srcset, for example, `[300, 600, 800]` | |
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.
| | `widths` | An array of pixel widths to overwrite the default generated srcset, for example, `[300, 600, 800]` | | |
| | `widths` | An array of pixel widths to overwrite the default generated srcset. For example, `[300, 600, 800]`. | |
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.
The suggestion was implemented but placed on a different line since the property was removed from this object.
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.
Thanks, @ejfranco06! I think it might be worthwhile making the same update here so that it coincides with the code comment added to the widths props in Image.tsx: https://github.com/Shopify/hydrogen/pull/1330/files#diff-420d9b9daba4583b071a7254c864b6af742c2eaf8cda82aa8859701745271864R70
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.
The updates are now included in the documentation.
Co-authored-by: Michelle Vinci <[email protected]>
Co-authored-by: Michelle Vinci <[email protected]>
mcvinci
left a comment
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.
Thanks, @ejfranco06! The docs changes look good to me. I'll defer to @frehner for a more comprehensive technical review.
Thank you for helping me improve the docs |
| }); | ||
| }); | ||
|
|
||
| it('generates a default srcset', () => { |
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 you duplicate this test but instead use src instead of data?
|
One last test addition request and then I think this is good to go! |
|
A test for external images using src with a loader and widths is now in the test suite |
frehner
left a comment
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.
(sorry for the delay, was at a burst) Thanks for your work!
* Center logo in Demo Store header (#1378) * Template favicons updated with SVGs, and moved to /src/assets (#1377) * Automatically fix GQL imports in exisiting Hydrogen Projects (#1336) * Add eslint rule to fix gql imports * Update README.md * add tests with fixer * Update packages/eslint-plugin/src/rules/prefer-gql/README.md Co-authored-by: Michelle Vinci <[email protected]> * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Final copy edits Co-authored-by: Michelle Vinci <[email protected]> * Remove CLI scripts (#1379) * Support ESLint v8 in `eslint-plugin` (#1373) * remove and reorganize duplicated content (#1380) * Simplify `routes` property in Hydrogen config (#1313) * Drop import.meta.globEager in dev * Refactor variables and virtual modules * Fix code after cherry-pick * Extract Vitception * Use Vitception to load routes during build * Use static imports to fix build * Add default routes path * Fix types and paths * Fix dirPrefix issues * Fix HMR in route files * Use default value for config.routes * Fix issue in Node 16.15 * Extract virtual-files plugin for clarity * Cleanup * Fix unit tests * Update docs * Changeset * Cleanup * Regenerate broken graphql.schema.json * Disable rules-of-hooks in server components * Disable prefer-gql in test * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Revert "Disable prefer-gql in test" This reverts commit d130f1c. * Revert "Disable rules-of-hooks in server components" This reverts commit e0ffbf6. Co-authored-by: Michelle Vinci <[email protected]> * Update formatting of release notes * minor fixes (#1391) * Remove hello world code (#1392) * [ci] release v1.x-2022-07 (#1343) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Remove broken changesets * [Hydrogen docs]: User authentication (#1353) * initial draft * remove useCustomer docs * add address and order routes * integrate feedback * Make graphql-tag a dep instead of a devDep to fix dev errors (#1394) * [ci] release v1.x-2022-07 (#1396) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * StackBlitz: turn off auto-save (#1386) * Simplify renderHydrogen internal logic (#1384) * Simplify entry-server code * Combine stream and render into runSsr * Rename some variables and functions for consistency * Fix: write head before checking redirects in Node * Remove unnecessary check and add comment * These li'l babies need a flipperoo (#1398) * Rename utility `isClient` to `isBrowser` (#1389) * Rename utility `isClient` to `isBrowser` * Switch to document check instead of window * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Update docs/utilities/isserver.md Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Fix unique key issue in old demo store template * Workers support streaming now (#1227) * I think streaming is supported now? * Bump * Add changeset * style guide fixes (#1407) * Move logger options to Hydrogen config (#1403) * Stop using globalThis for logger and minor refactor * Move logger options to Hydrogen config file * Update unit tests * Remove setLogger call from e2e tests * Always call setLogger for HMR * Remove unnecessary type * Add docs * Changeset * Fix link * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Fix CountrySelector styling in demo store (#1415) * fix-demo-store-country-selector-styling * move conditional classes back to newline * add changeset * Fix logger title in docs (#1419) * Fix logger title in docs * Fix unrelated changeset * Suppress confusing warnings (#1399) * Supress confusing warnings * Changeset * Typo * Improve component bundling and reduce total downloaded files (#1361) * Skip module references for nested client components * Changeset * Move Viteception to RSC plugin. Augment Vite module graph. Bundle client components in boundary chunks * Minor refactor of internal components to reduce generated chunks * Changeset * Update plugin with latest changes * Maybe fix Windows paths * Fix undefined variable * Add moduleSideEffects info * Sync React experimental with upstream * Deprecate `enableStreaming` (#1401) * Deprecate enableStreaming option * Changeset * Add docs * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Fix link Co-authored-by: Michelle Vinci <[email protected]> * Move client options to Hydrogen config (#1418) * Move client options to Hydrogen config * Update docs * Changeset * Remove global config (#1422) * Remove global config * Fix unit tests * Move global context to request internals (#1423) * Move global context to request internals * Changeset Co-authored-by: Josh Larson <[email protected]> * Support async logs (#1424) * Move global context to request internals * Changeset * Support async logs * Change docs example * Changeset * Make sure waitUntil exists Co-authored-by: Josh Larson <[email protected]> * Rename internal Hydrogen global variables (#1425) * Rename hydrogen globals * Changeset Co-authored-by: Josh Larson <[email protected]> * Rename Request/Response classes to `HydrogenRequest` and `HydrogenResponse` (#1408) * Rename `ServerComponentRequest` to `HydrogenRequest` * Move `HydrogenRequest` out of weird Hydration folder * Move test, too * Rename `ServerComponentResponse` to `HydrogenResponse` * Update old references of names * Fix broken references * Call out breaking changes in changesets * Move non-CJS files out of `framework` into `foundation` (#1409) * Move HydrogenRequest to foundation * Move HydrogenResponse to foundation * Move HydrogenRequest test * Move Cache things to foundation * Move runtime to foundation * Move Html to foundation * Move rsc stuff to entry-client * StackBlitz: temporary start command workaround (#1434) * Ignore skipped tests to avoid CI noise (#1432) * Support Node 18 by avoiding `Headers.raw()` (#1427) * Split cookies manually instead of using `Headers.raw()` * Add Node v18 to the testing matrix * Add changeset * Fix types, logic, and bundling issues * Add support for sending ReadableStream to node responses * Update set-cookie-parser to enhance tree-shaking in workers * Update packages/hydrogen/src/entry-server.tsx Co-authored-by: Fran Dios <[email protected]> * Use existing bufferReadableStream utility * Don't run tests on Node 17 anymore Co-authored-by: Fran Dios <[email protected]> * Implement the account details pages (#1334) * add account create form add login form move login to api route and set it in response & server get e2e login & logout working remove setting cookie directly into the server simplify logout simplify login condition render account route using customerAccessToken add account icon link rename account route and add no cache add no cache to customer related query & mutation move login form to a different route add register & recover route and create account folder add account creation flow fix account login redirect replace cookie module with worktop/cookie add checking to account details add customer recover form add password reset flow add more test to cart provider refactor useCookie to useCustomer instead if user logined already, use the access token for cart creation explore multipass login fix up customer related toolings using sessions remove @shopify/react-form from login Remove @shopify/react-form from account create remove @shopify/react-form from password recover remove @shopify/react-form from password reset remove @shopify/react-form * Fixes * Fix lint problems * Fix error handling on account creation * Fixes to login form * Fix layout for desktop * Fix create account page * Fix recovery page * Fixes * Fixes * Move AccountProfile image to a static svg * Remove multipass stuff for now * Mo fixes * Fix lint errors * Add docs * Add docs and changeset * Update the useCustomer hook * Update docs/hooks/global/usecustomer.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/global/usecustomer.md Co-authored-by: Michelle Vinci <[email protected]> * Prevent account pages from being indexed by bots * Update docs * Remove multipassify for now * Fix verbiage * Fix docs * Add activate account page and move client components into common directory * Fix gql * Remove `useCustomer` hooks * Implement account pages * Fixes * Fixes * Fix bad merge * Fixes Co-authored-by: Michelle Chen <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Allow scroll restoration to be disabled (#1431) * Allow scroll restoration to be disabled * Update examples * Revert to prior default value * Always restore scroll on pop events, regardless of initial intent * Change to `scroll` Co-authored-by: Bret Little <[email protected]> * [Hydrogen docs]: Specify experimental features (#1445) * call out experimental features * add experimental note to showqueryTiming option * [Hydrogen docs]: Remove references to render props (#1442) * remove references to render props * reference customizing components section * typo fixes (#1446) * fix note (#1448) * [Hydrogen docs]: Update app scaffolding commands (#1292) * update commands * typo * typo * Remove writeHead and make status writable (#1433) * Remove writeHead and make status writable * Changeset * Cleanup * Add highWaterMark default to React Flight readable (#1451) * Improve CPU performance in RSC (#1452) * Improve CPU performance in RSC check * Changeset * Generate a default srcset for an image returned by the Shopify CDN (#1330) * feat: add default img srcset to Shopify images * feat: add custom widths to Image srcset * doc: add srcset documentation * doc: add change set * feat: lift widths prop to Image level * feat: use the available loader to generate srcset * feat:reduce srcset to max-width without distortion * test: add default img srcset test * Update packages/hydrogen/src/components/Image/Image.tsx Co-authored-by: Michelle Vinci <[email protected]> * doc: update Image docs with widths prop changes * feat: generate srcset for extarnal images * Update docs/components/primitive/image.md Co-authored-by: Michelle Vinci <[email protected]> * test: add test for images using src Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Anthony Frehner <[email protected]> * Improve error message when storefront API is not JSON (#1444) * Propagate a better error message when the response from the storefront API is not JSON parseable * Shopify analytics 2 (#1325) * Instrumented page view and make sure Shopfiy live view works Co-authored-by: Michelle Vinci <[email protected]> * [ci] release v1.x-2022-07 (#1404) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Get changelogs to see the new name * Try to retrigger changeset (#1459) * Product provider work (#1397) * saving progress * Saving progress I think I have the code all working, it's now just updating tests and stuff. I updated the docs but they probably need to be cleaned up more. * Working on tests * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productprice.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/product-variant/useproductoptions.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/product-variant/useproductoptions.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Get tests passing and fix a lot of issues in the meantime * Update docs to show nodes instead of edges->node * Replace ProductProvider with ProductOptionsProvider * Fix issue with useEffect * update selectedoptions on initialVariantId change Co-authored-by: Michelle Vinci <[email protected]> * Fix doc links (#1460) * fix doc links * add changeset * Remove demo-store frontmatter * Revert "[ci] release v1.x-2022-07 (#1404)" (#1462) This reverts commit c05c999. * [ci] release v1.x-2022-07 (#1461) * [ci] release v1.x-2022-07 * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Anthony Frehner <[email protected]> * fix link (#1463) * Lint changesets (#1464) * Add script to lint changesets * Add note about avoiding headings as first line of changesets, and a linter for that * Add more specific actionable stuff * Try removing emoji * Revert "Try removing emoji" This reverts commit 2ce6301. * Add final success message * Remove unused dependencies (#1457) Co-authored-by: Anthony Frehner <[email protected]> * Cart types update (#1237) * saving progress * update queries, types, and add documentation * Saving progress; I think I'm done but the SFAPI may be down? * Update docs * Update .changeset/wet-dingos-kick.md Co-authored-by: Josh Larson <[email protected]> * Update types and make a small update to CartLinePrice Co-authored-by: Josh Larson <[email protected]> * Updates yarn lock * Remove unconfig vite files * Moves demo-store to demo-store-neue folder * Moves demo-store-archive to demo-store * Replaces dynamic import with CSS classes * Temp switch to non-aliased Header/Footer imports to fix dev * Removes unconfig vite file * Updates Favicon design * Hides cart badge when 0 * Fixes Product Page with updated ProductOptionsProvider * Updates Cart page for dark mode and Icon colors * Fixes broken query on Collection page * Fixes imports and other linting errors across several files * Fix `ProductGrid` * Fix locations index route Co-authored-by: Matt Seccafien <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Fran Dios <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Bret Little <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Scott Dixon <[email protected]> Co-authored-by: BradMurchison <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Michelle Chen <[email protected]> Co-authored-by: Emilio Franco <[email protected]> Co-authored-by: Anthony Frehner <[email protected]> Co-authored-by: Helen Lin <[email protected]> Co-authored-by: Daniel Rios Pavia <[email protected]>
* Inits new demo store template * Update package.json * Use `gql` from `hydrogen` in demo store v2 * Remove server utilities from client build (#1363) * Remove server utilities from client build * Changeset Co-authored-by: Josh Larson <[email protected]> * remove stray console.log (#1364) * Prevent encoded props from double decoding (#1360) * Prevent encoded props from double decoding in the RSC flight inlined in the initial page load * Removed unused htmlDecode * Update stackblitz workflow to manually update files (#1365) This needs to happen in a single commit as opposed to concurrent/parallel workflows because they both check out the main branch first and then force push. * Add rule override (#1367) * Adds @types/react to typescript example (#1362) * Update docs to describe the difference between experimental and unstable releases (#1366) * Explicitly log errors for Flight onError (#1320) * wip: Explicitly log errors for Flight onError * Rename variables for clarity * Add changeset * Revert streaming thing * Bump hydrogen eslint plugin version (#1368) * Bump hydrogen eslint plugin version This gets rid of the annoying error we're seeing while developing the monorepo * Use new name for hook * Update for more lax server component hooks rules * Drop prefixes from template names (#1369) * Drop prefixes from template names * Update publish_stackblitz.yml * Update index.server.jsx * Update index.server.jsx * Typescript updates (#1374) * Update typescript and ts-node ts-node was required to update because of this comment jestjs/jest#12655 (comment) * Dedupe the react/types and finish the update * Fix Image typescript issues (#1371) * Add TS test-ish things for Image's TS types Make any console.warn only happen in dev Fix Image's weird types issue with Simplify from type-fest Update the readme for the TS example * Fix dev warnings and a type issue * add changelog * Update yarn.lock * Adds basic layout components and content for 404 * @benjaminsehl/demo store neue (#1387) * Adds basic components for Collection. Refines Product Card. Co-locates mock data. * Adds Locations page, refines existing components * Runs yarn format * Updates Icons to work with SSR * Removes custom spacing from Tailwind config * Updates temp country banner * Refactors product card, adds search page, beginning of product page * Adds search functionality, adds real data to homepage, improves components * Completes desktop hero with dynamic data * Improves layout and adds data for homepage, cart, header, product card, collections, swimlane * Updates to locations, collections, products all * Style consistency updates and addition of dark mode * Adds functioning search bar on search page * Adds queries and dynamic data for components * Update styling on hero and search * Yarn format * Updates to hero and search * Revert "Updates to hero and search" This reverts commit 145defe. * Style tweaks to header * Complete locations template * Update Location template layout * Demo store neue: collection pagination (#1400) * Dynamic Product Swimlane & Mobile Layouts (#1412) * Product Swimlane now works with product recommendations * Updates Header for mobile * Mobile layout for header, footer, and key layout components * Adds expanding menus to footer * Adds mobile layout for search * @benjaminsehl/pdp demo store neue (#1414) * Product Swimlane now works with product recommendations * Updates Header for mobile * Mobile layout for header, footer, and key layout components * Adds expanding menus to footer * Adds mobile layout for search * Basic product page layout * Adds URL param control to PDP * Added account pages from demo-store (#1410) * Added account pages from demo-store * Autofocus email and password inputs * adds cart functionality (#1417) * Wire up cart page * Fixes typeof error in swimlane * Wires up cart data * Demo store neue: Intersection Observer for infinite scroll (#1421) Co-authored-by: Benjamin Sehl <[email protected]> * Dy orders (#1420) * wip - display empty state for order history if customer doesn't have any orders yet * Updated empty state based on 404 page * Display custom welcome heading if customer account has a first name * Added featured collections, products, and locations sections to account details page * Styling updates on forms * Styling, padding, alignment for order history * Demo store neue: clean up country selector (#1436) * Renames metaobjects to contentEntries * Updates metaobject references to contentEntry * Minor visual fixes and a catch for a bug with availableOnSale * Moves Neue to main demo store, moves existing demo store to demo-store-archive * Display order history as a grid of cards (#1440) * Display order history as grid of cards * Use Text component * Fixed text spacing * Fix new demo store build after update to [email protected] (#1454) * Remove package-lock file * Update to `@shopify/[email protected]` and `@shopify/[email protected]` * Remove `graphql-tag` * Update yarn lock file with latest new demo store changes * Fix environment variable in `App.server.jsx` * Use default routes in hydrogen config * Revert "Fix new demo store build after update to [email protected] (#1454)" This reverts commit ba43a31. Easier to merge 0.23.0 and then update given the name changes in folders causing too many conflicsts * Upgrade Demo Store Neue to v23 (#1467) * Center logo in Demo Store header (#1378) * Template favicons updated with SVGs, and moved to /src/assets (#1377) * Automatically fix GQL imports in exisiting Hydrogen Projects (#1336) * Add eslint rule to fix gql imports * Update README.md * add tests with fixer * Update packages/eslint-plugin/src/rules/prefer-gql/README.md Co-authored-by: Michelle Vinci <[email protected]> * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Final copy edits Co-authored-by: Michelle Vinci <[email protected]> * Remove CLI scripts (#1379) * Support ESLint v8 in `eslint-plugin` (#1373) * remove and reorganize duplicated content (#1380) * Simplify `routes` property in Hydrogen config (#1313) * Drop import.meta.globEager in dev * Refactor variables and virtual modules * Fix code after cherry-pick * Extract Vitception * Use Vitception to load routes during build * Use static imports to fix build * Add default routes path * Fix types and paths * Fix dirPrefix issues * Fix HMR in route files * Use default value for config.routes * Fix issue in Node 16.15 * Extract virtual-files plugin for clarity * Cleanup * Fix unit tests * Update docs * Changeset * Cleanup * Regenerate broken graphql.schema.json * Disable rules-of-hooks in server components * Disable prefer-gql in test * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Revert "Disable prefer-gql in test" This reverts commit d130f1c. * Revert "Disable rules-of-hooks in server components" This reverts commit e0ffbf6. Co-authored-by: Michelle Vinci <[email protected]> * Update formatting of release notes * minor fixes (#1391) * Remove hello world code (#1392) * [ci] release v1.x-2022-07 (#1343) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Remove broken changesets * [Hydrogen docs]: User authentication (#1353) * initial draft * remove useCustomer docs * add address and order routes * integrate feedback * Make graphql-tag a dep instead of a devDep to fix dev errors (#1394) * [ci] release v1.x-2022-07 (#1396) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * StackBlitz: turn off auto-save (#1386) * Simplify renderHydrogen internal logic (#1384) * Simplify entry-server code * Combine stream and render into runSsr * Rename some variables and functions for consistency * Fix: write head before checking redirects in Node * Remove unnecessary check and add comment * These li'l babies need a flipperoo (#1398) * Rename utility `isClient` to `isBrowser` (#1389) * Rename utility `isClient` to `isBrowser` * Switch to document check instead of window * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Update docs/utilities/isserver.md Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Fix unique key issue in old demo store template * Workers support streaming now (#1227) * I think streaming is supported now? * Bump * Add changeset * style guide fixes (#1407) * Move logger options to Hydrogen config (#1403) * Stop using globalThis for logger and minor refactor * Move logger options to Hydrogen config file * Update unit tests * Remove setLogger call from e2e tests * Always call setLogger for HMR * Remove unnecessary type * Add docs * Changeset * Fix link * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Fix CountrySelector styling in demo store (#1415) * fix-demo-store-country-selector-styling * move conditional classes back to newline * add changeset * Fix logger title in docs (#1419) * Fix logger title in docs * Fix unrelated changeset * Suppress confusing warnings (#1399) * Supress confusing warnings * Changeset * Typo * Improve component bundling and reduce total downloaded files (#1361) * Skip module references for nested client components * Changeset * Move Viteception to RSC plugin. Augment Vite module graph. Bundle client components in boundary chunks * Minor refactor of internal components to reduce generated chunks * Changeset * Update plugin with latest changes * Maybe fix Windows paths * Fix undefined variable * Add moduleSideEffects info * Sync React experimental with upstream * Deprecate `enableStreaming` (#1401) * Deprecate enableStreaming option * Changeset * Add docs * Apply suggestions from code review Co-authored-by: Michelle Vinci <[email protected]> * Fix link Co-authored-by: Michelle Vinci <[email protected]> * Move client options to Hydrogen config (#1418) * Move client options to Hydrogen config * Update docs * Changeset * Remove global config (#1422) * Remove global config * Fix unit tests * Move global context to request internals (#1423) * Move global context to request internals * Changeset Co-authored-by: Josh Larson <[email protected]> * Support async logs (#1424) * Move global context to request internals * Changeset * Support async logs * Change docs example * Changeset * Make sure waitUntil exists Co-authored-by: Josh Larson <[email protected]> * Rename internal Hydrogen global variables (#1425) * Rename hydrogen globals * Changeset Co-authored-by: Josh Larson <[email protected]> * Rename Request/Response classes to `HydrogenRequest` and `HydrogenResponse` (#1408) * Rename `ServerComponentRequest` to `HydrogenRequest` * Move `HydrogenRequest` out of weird Hydration folder * Move test, too * Rename `ServerComponentResponse` to `HydrogenResponse` * Update old references of names * Fix broken references * Call out breaking changes in changesets * Move non-CJS files out of `framework` into `foundation` (#1409) * Move HydrogenRequest to foundation * Move HydrogenResponse to foundation * Move HydrogenRequest test * Move Cache things to foundation * Move runtime to foundation * Move Html to foundation * Move rsc stuff to entry-client * StackBlitz: temporary start command workaround (#1434) * Ignore skipped tests to avoid CI noise (#1432) * Support Node 18 by avoiding `Headers.raw()` (#1427) * Split cookies manually instead of using `Headers.raw()` * Add Node v18 to the testing matrix * Add changeset * Fix types, logic, and bundling issues * Add support for sending ReadableStream to node responses * Update set-cookie-parser to enhance tree-shaking in workers * Update packages/hydrogen/src/entry-server.tsx Co-authored-by: Fran Dios <[email protected]> * Use existing bufferReadableStream utility * Don't run tests on Node 17 anymore Co-authored-by: Fran Dios <[email protected]> * Implement the account details pages (#1334) * add account create form add login form move login to api route and set it in response & server get e2e login & logout working remove setting cookie directly into the server simplify logout simplify login condition render account route using customerAccessToken add account icon link rename account route and add no cache add no cache to customer related query & mutation move login form to a different route add register & recover route and create account folder add account creation flow fix account login redirect replace cookie module with worktop/cookie add checking to account details add customer recover form add password reset flow add more test to cart provider refactor useCookie to useCustomer instead if user logined already, use the access token for cart creation explore multipass login fix up customer related toolings using sessions remove @shopify/react-form from login Remove @shopify/react-form from account create remove @shopify/react-form from password recover remove @shopify/react-form from password reset remove @shopify/react-form * Fixes * Fix lint problems * Fix error handling on account creation * Fixes to login form * Fix layout for desktop * Fix create account page * Fix recovery page * Fixes * Fixes * Move AccountProfile image to a static svg * Remove multipass stuff for now * Mo fixes * Fix lint errors * Add docs * Add docs and changeset * Update the useCustomer hook * Update docs/hooks/global/usecustomer.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/global/usecustomer.md Co-authored-by: Michelle Vinci <[email protected]> * Prevent account pages from being indexed by bots * Update docs * Remove multipassify for now * Fix verbiage * Fix docs * Add activate account page and move client components into common directory * Fix gql * Remove `useCustomer` hooks * Implement account pages * Fixes * Fixes * Fix bad merge * Fixes Co-authored-by: Michelle Chen <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> * Allow scroll restoration to be disabled (#1431) * Allow scroll restoration to be disabled * Update examples * Revert to prior default value * Always restore scroll on pop events, regardless of initial intent * Change to `scroll` Co-authored-by: Bret Little <[email protected]> * [Hydrogen docs]: Specify experimental features (#1445) * call out experimental features * add experimental note to showqueryTiming option * [Hydrogen docs]: Remove references to render props (#1442) * remove references to render props * reference customizing components section * typo fixes (#1446) * fix note (#1448) * [Hydrogen docs]: Update app scaffolding commands (#1292) * update commands * typo * typo * Remove writeHead and make status writable (#1433) * Remove writeHead and make status writable * Changeset * Cleanup * Add highWaterMark default to React Flight readable (#1451) * Improve CPU performance in RSC (#1452) * Improve CPU performance in RSC check * Changeset * Generate a default srcset for an image returned by the Shopify CDN (#1330) * feat: add default img srcset to Shopify images * feat: add custom widths to Image srcset * doc: add srcset documentation * doc: add change set * feat: lift widths prop to Image level * feat: use the available loader to generate srcset * feat:reduce srcset to max-width without distortion * test: add default img srcset test * Update packages/hydrogen/src/components/Image/Image.tsx Co-authored-by: Michelle Vinci <[email protected]> * doc: update Image docs with widths prop changes * feat: generate srcset for extarnal images * Update docs/components/primitive/image.md Co-authored-by: Michelle Vinci <[email protected]> * test: add test for images using src Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Anthony Frehner <[email protected]> * Improve error message when storefront API is not JSON (#1444) * Propagate a better error message when the response from the storefront API is not JSON parseable * Shopify analytics 2 (#1325) * Instrumented page view and make sure Shopfiy live view works Co-authored-by: Michelle Vinci <[email protected]> * [ci] release v1.x-2022-07 (#1404) Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Get changelogs to see the new name * Try to retrigger changeset (#1459) * Product provider work (#1397) * saving progress * Saving progress I think I have the code all working, it's now just updating tests and stuff. I updated the docs but they probably need to be cleaned up more. * Working on tests * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productprice.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/product-variant/useproductoptions.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/hooks/product-variant/useproductoptions.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Update docs/components/product-variant/productoptionsprovider.md Co-authored-by: Michelle Vinci <[email protected]> * Get tests passing and fix a lot of issues in the meantime * Update docs to show nodes instead of edges->node * Replace ProductProvider with ProductOptionsProvider * Fix issue with useEffect * update selectedoptions on initialVariantId change Co-authored-by: Michelle Vinci <[email protected]> * Fix doc links (#1460) * fix doc links * add changeset * Remove demo-store frontmatter * Revert "[ci] release v1.x-2022-07 (#1404)" (#1462) This reverts commit c05c999. * [ci] release v1.x-2022-07 (#1461) * [ci] release v1.x-2022-07 * Update CHANGELOG.md * Update CHANGELOG.md Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Anthony Frehner <[email protected]> * fix link (#1463) * Lint changesets (#1464) * Add script to lint changesets * Add note about avoiding headings as first line of changesets, and a linter for that * Add more specific actionable stuff * Try removing emoji * Revert "Try removing emoji" This reverts commit 2ce6301. * Add final success message * Remove unused dependencies (#1457) Co-authored-by: Anthony Frehner <[email protected]> * Cart types update (#1237) * saving progress * update queries, types, and add documentation * Saving progress; I think I'm done but the SFAPI may be down? * Update docs * Update .changeset/wet-dingos-kick.md Co-authored-by: Josh Larson <[email protected]> * Update types and make a small update to CartLinePrice Co-authored-by: Josh Larson <[email protected]> * Updates yarn lock * Remove unconfig vite files * Moves demo-store to demo-store-neue folder * Moves demo-store-archive to demo-store * Replaces dynamic import with CSS classes * Temp switch to non-aliased Header/Footer imports to fix dev * Removes unconfig vite file * Updates Favicon design * Hides cart badge when 0 * Fixes Product Page with updated ProductOptionsProvider * Updates Cart page for dark mode and Icon colors * Fixes broken query on Collection page * Fixes imports and other linting errors across several files * Fix `ProductGrid` * Fix locations index route Co-authored-by: Matt Seccafien <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: Fran Dios <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Bret Little <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Scott Dixon <[email protected]> Co-authored-by: BradMurchison <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Michelle Chen <[email protected]> Co-authored-by: Emilio Franco <[email protected]> Co-authored-by: Anthony Frehner <[email protected]> Co-authored-by: Helen Lin <[email protected]> Co-authored-by: Daniel Rios Pavia <[email protected]> * Remove package lock file * Temporarily comment out missing account components and fixes small issues * Update to `[email protected]` * Fix graphql schema Co-authored-by: Benjamin Sehl <[email protected]> Co-authored-by: Matt Seccafien <[email protected]> Co-authored-by: Fran Dios <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Bret Little <[email protected]> Co-authored-by: JrFelix540 <[email protected]> Co-authored-by: Anthony Frehner <[email protected]> Co-authored-by: Scott Dixon <[email protected]> Co-authored-by: Dave Yen <[email protected]> Co-authored-by: Michelle Vinci <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: BradMurchison <[email protected]> Co-authored-by: Josh Larson <[email protected]> Co-authored-by: Michelle Chen <[email protected]> Co-authored-by: Emilio Franco <[email protected]> Co-authored-by: Helen Lin <[email protected]>
Description
The Image component is only using src to load images. When an image is wider than the viewport, the user downloads more data than they need slowing down their page load. By using srcsets, the browser can determine the best size that requires the least data. This PR would auto-generate a srcset for Images using the Shopify CDN.
The default image sizes are
[352, 832, 1200, 1920, 2560]these extend the defaults used by Shopify's liquid HTML image tagimage_tagThe user can define their custom sizes with the Image size options propertywidths, for example,[200, 300, 400]. The custom sizes work in a similar way to the liquidimage_tag: widths: '200, 300, 400'worksThese improvements would benefit the requested image improvements in #1223 by adding best practices into the image by default while still allowing customization.
Additional context
The functionality, naming, and order are based on the Liquid HTML tag for Images. Link for reference
image_tag.Before submitting the PR, please make sure you do the following:
fixes #123)yarn changeset addif this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning