hydrogen-react has become a sub-package in the Hydrogen monorepo.
Here is a direct link to the source code: https://github.com/Shopify/hydrogen/tree/main/packages/hydrogen-react
Reusable components and utilities for building Shopify-powered custom storefronts.
Home Page: https://shopify.dev/docs/api/hydrogen-react
License: MIT License
hydrogen-react has become a sub-package in the Hydrogen monorepo.
Here is a direct link to the source code: https://github.com/Shopify/hydrogen/tree/main/packages/hydrogen-react
Describe the bug
Using in _app throws the error:
Warning: useLayoutEffect does nothing on the server, because its effect cannot be encoded into the server renderer's output format. This will lead to a mismatch between the initial, non-hydrated UI and the intended UI. To avoid this, useLayoutEffect should only be used in components that render exclusively on the client. See https://reactjs.org/link/uselayouteffect-ssr for common fixes.
- "@shopify/hydrogen-react": "^2022.10.2"
- "next": "^13.0.3"
- Node v16.17.1
CartLineQuantityAdjustButton disabled prop needs to come after passthroughProps, otherwise our custom logic gets wiped out by passthrough props.
hydrogen-react/packages/react/src/CartLineQuantityAdjustButton.tsx
Lines 65 to 70 in 9f025d3
Create a component that uses SF API's CartLineCost
to render the estimated cost of a cart line after discounts.
More details to be added.
Describe the bug
Storefront client incorrectly warns "You are attempting to use a private token in an environment where it can be easily accessed by anyone." when running from code on the server.
The cause
In packages/react/src/storefront-client.ts, line 50 the condition used to show the warning checks if globalThis is truthy instead of checking if globalThis.document is truthy. globalThis is defined on both servers and clients.
To Reproduce
Steps to reproduce the behavior:
Using npm doesn't seem to trigger the warning as it seems to use the "default" module exports instead of the "developer" module exports. The default module exports (production exports) do not contain this warning.
Expected behavior
Code running on the server does not warn about using a private token.
Describe the bug
When using the CartLineQuantityAdjustButton
component, any lineItem
attributes already present on the item are cleared when using the component - increasing or decreasing.
Underlying Issue
In CartLineQuantityAdjustButton.tsx#L36
linesUpdate([{id: cartLine.id, quantity}]);
To Reproduce
Add a product to cart and the lineItem will include:
"attributes": [
{
"key": "Custom",
"value": "Hello world"
}
]
Increasing the quantity in the cart removes the attributes:
"attributes": []
Expected behaviour
The assumption is that any attributes already attached to the lineItem should be left intact when altering the quantity since the lineItem
is the same.
Is your feature request related to a problem? Please describe.
Today, we hardcode a trailing myshopify.com
to the developer's storefront domain when creating the storefront client: https://github.com/Shopify/hydrogen-ui/blob/2022-10/packages/react/src/storefront-client.ts#L44-L48
This is because it represents the "permanent domain" for a Shopify storefront, and because it's the most commonly used format.
However, technically any domain pointed at the storefront can field API requests, not just the permanent domain.
Specifically, this unlocks:
Describe the solution you'd like
The shop domain should respect whatever value I provide to it.
TypeError: _virtual_with_selector_mjs__WEBPACK_IMPORTED_MODULE_4__.w.exports.useSyncExternalStoreWithSelector is not a function
Using react 18.2.0
Is your feature request related to a problem? Please describe.
<ShopifyProvider />
documentation is wrong, and doesn't reflect update to shopifyConfig
prop
Describe the solution you'd like
Docs updated :]
https://shopify.dev/api/hydrogen/components/global/shopifyprovider#shopifyprovider-in-alternate-frameworks
Is your feature request related to a problem? Please describe.
We currently define an enum called ShopifyAppSource
to disambiguate between the Hydrogen and Custom Storefronts channel: https://github.com/Shopify/storefront-kit-react/blob/6184517a2bf2b62198f8601ff798d851b604d386/packages/react/src/analytics-constants.ts#L31
It's probably called this because it's literally referring to an "API Client ID" aka an internal app.
However, this is an internal concern and not a merchant- or dev-facing concern.
This is confusing, because it indicates to me that an "app" is somehow involved with me, an external-facing developer or merchant.
Describe the solution you'd like
Instead, we should call this something like ShopifyChannelType
.
During #171 we did another audit of what we have in this package and what we were supposed to have in this package. It was discovered that there are two things missing, and one thing in this package that wasn't supposed to be. A breakdown:
We need to deprecate & remove at next major:
We need to add:
export helper for TypeScript + GraphQL codegen to assign correct usage of SFAPI custom scalars. For example, by default the URL scalar is any
- but we know it is actually a string
createStorefrontClient takes in storeDomain like so:
storeDomain: 'hydrogen-preview',
ShopifyProvider takes in storeDomain like so:
storeDomain: `hydrogen-preview.myshopify.com`,
That's annoying and unnecessary. In addition, #70 was just merged that adds a function for getting the fully-qualified URL to createStorefrontClient, which includes the https://
. So it would be good to add that to ShopifyProvider, too.
I feel like ideally we go the createStorefrontClient route and only ask for the name (e.g. just hydrogen-preview
, and not hydrogen-preview.myshopify.com
), but I'm open to other ideas.
Enable devs to report bugs/issues easily by providing a Stackblitz to reproduce them
Describe the bug
When fetching the cart with Hydrogen builtin components, the cart and its products is fetched in the default language - not in a selected language.
When looking at the source graphql query, only the countryCode
is taking into account, not the languageCode
:
To Reproduce
Fetch a cart with a product. It won't take the selected language into account.
Expected behaviour
Fetch the cart and its products in a given language.
Additional context
Add any other context about the problem here. eg.
Components to be removed:
CartLineImage
CartLineProductTitle
CartLines
Describe the bug
When adding multiple discounts to a cart with cartCreate() from useCart() it only adds the first discount in the array provided.
To Reproduce
Create a cart using cartCreate()
cartCreate({ discountCodes: ['discount_1', 'discount_2', 'discount_3'], lines: line_items })
Go to checkout with that cart and see that only 'discount_1' is added.
Expected behaviour
It should add all discounts provided in the array of discounts.
Additional context
Since Shopify now supports multiple discounts it should be supported by Hydrogen stores as well.
The useMoney() example references a variable named variant which is undefined
Is your feature request related to a problem? Please describe.
Now that you can now create Rich Text metafields in the admin it would be great to be able to easily parse them using parseMetafield
inside of React Storefront Kit. The rich_text_field
type doesn't seem to be currently supported
Describe the solution you'd like
Recognizing the rich_text_field
and translating the value to either an HTML string or React Nodes.
Describe alternatives you've considered
I've created a utility based on experimenting with the JSON format but an official solution would probably be best when we deploy.
As I was building the guides for hydrogen 2, some of the feedback I received was that wrapping the whole app in just to use the Shop Pay button felt strange.
Snooping on the code a bit, it looks like the only code that is being pulled from the provider is the shop ID.
Describe the solution you'd like
Include 2 ways to use Shop Pay button (and other components where it makes sense).
If wrapped in a Provider, you don't need to pass in props like shop ID.
If not wrapped in a Provider, you can pass in props to the component.
Additional context
I think the overall goal is to have something copy/pasteable that works in any context.
We need to add the ability to purchase product(s) with Google Pay.
In Shopify storefronts with Liquid, there are two use cases for the Google Pay button:
DynamicCheckoutButton
component when appropriateDynamicCheckoutButton
component has a really rough first pass on displaying the GooglePay button (see code here. We'll likely want to extract this code into its own component GooglePayButton
and iterate on it from there.Describe the bug
Using the buyerIdentityUpdate function from the useCart hook, doesn't respect the deliveryAddressPreferences object entered.
To Reproduce
buyerIdentityUpdate({
countryCode: 'GB',
email: '[email protected]',
phone: '123412344',
deliveryAddressPreferences: [{
deliveryAddress: {
address1: '1',
address2: '2',
city: 'London',
country: 'GB',
firstName: 'Test',
lastName: 'Example',
phone: '123412344',
zip: 'SW12 1JG',
province: 'London',
}
}]
})
Expected behavior
Shipping address to be populated
Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here.
Is there a reason Analytics is supported in Hydrogen but not -ui?
Describe the bug
Importing and using anything from @shopify/hydrogen-react
in a client component in a Hydrogen project causes the following error.
Error: Failed to resolve entry for package "@shopify/hydrogen-react". The package may have incorrect main/module/exports specified in its package.json
I run into this when attempting to use the new metafieldParser
function introduced with #45, but I can replicate this by trying to use anything from the library.
To Reproduce
yarn add @shopify/hydrogen-react
)import { Metafield } from '@shopify/hydrogen-react'
)<Metafield data={metafield} />
)yarn run dev
)Expected behavior
Using the Hydrogen UI library in a Hydrogen project shouldn't throw an error.
Additional context
2022.10.4
Hydrogen
16.18.0
Google Chrome Version 107.0.5304.110 (Official Build) (64-bit)
Describe the bug
I'm using a custom cart fragment to also fetch discountAllocations
from the API. They properly update when adding a coupon using discountCodesUpdate
, but when I remove a coupon, the discount is still being allocated to the cart. In the checkout, there is no discount applied anymore (as expected).
I guess this is more of an API problem rather than a bug in the Hydrogen React framework, but maybe you can still help or forward this issue to the API team.
Expected behavior
There should be no more discountAllocations applied to the cart after all discount codes have been removed.
Screenshots
No discount codes, but discount is still being applied
Additional context
Describe the bug
When adding items to the shopping cart with AddToCartButton using attributes passed through the attributes prop, the attributes later appear to be overridden and removed if the quantity for that cart line is adjusted using CartLineQuantityAdjustButton.
To Reproduce
https://stackblitz.com/edit/shopify-hydrogen-n3hfqc
I have minimally modified this to pass attributes through the AddToCartButton in ProductForm.client.jsx, and to display any attributes in the CartLineItem.client.jsx. To reproduce the bug, add an item to the shopping cart. It should show the attribute 'Test: Testing' when you open the shopping cart.
Once the quantity is increased, the 'Test: Testing' attribute disappears.
Expected behaviour
I expected attributes to be retained unchanged when the quantity of the cart line item is adjusted.
Screenshots
If applicable, add screenshots to help explain your problem.
We need to add the ability to purchase with PayPal Express when the merchant has it enabled.
PayPal Express currently appears in two places in Liquid Shopify storefronts:
DynamicCheckoutButton
componentDynamicCheckoutButton
component has a really rough first pass on displaying the PayPal button (see code here). We'll likely want to extract this code into its own component PayPalButton
and iterate on it from there.I think it would be nice to include that ruleset for eslint, especially since it's also recommended to include it as a default.
https://typescript-eslint.io/linting/typed-linting
However, there appears to be issues with the TS parser + ESLint configs and our *.example.(t|j)sx
files; no matter what sort of configuration I attempt, those files still aren't "picked up" by TS+Eslint and there are errors with them. I've followed https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file and other guides and still get the error.
If we could work that out, then it would be nice as there are a bunch of errors+warnings that arise in the rest of our files because of that preset.
There's a chance that this repo get pulled back into the main hydrogen repo. If it does, then we'll need to migrate from yarn to npm.
I'll leave this as "blocked" for now as we aren't fully sure if that's going to happen or not
Describe the bug
The parseMetafield
and parseMetafieldValue
utilities don't return an array of strings for metafields of type list.single_line_text_field
.
To Reproduce
parseMetafield
orparseMetafieldValue
Expected behaviour
The parseMetafield
and parseMetafieldValue
utilities should return an array of strings instead of a stringified array for this type of metafield.
Additional context
1.3.2
16.14.0
iMac (macOS Monterey 12.4)
Describe the bug
Typscript className prop does not exist on MediaFile. On the StackBlitz, the rendered tag does take the className even though TS shows an error. However, on my dev environment I get the error and the
tag does not render the className.
Expected behaviour
Passing className to MediaFile should render the media tag with the passed class name string.
Is your feature request related to a problem? Please describe.
Hydrogen UI discoverability (not a problem, but this issue is to help with that)
Describe the solution you'd like
Update https://shopify.dev/custom-storefronts/tools for Hydrogen UI
Describe alternatives you've considered
/tools
cc. @elisenyang
CONTRIBUTING.md
file from the root readmeprobably more to be added 🙂
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.