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

ProductProvider provides incorrect selectedVariant when data prop is changed #1879

Open
tiwac100 opened this issue Mar 20, 2024 · 1 comment

Comments

@tiwac100
Copy link
Contributor

What is the location of your example repository?

No response

Which package or tool is having this issue?

hydrogen-react

What version of that package or tool are you using?

^2024.1.1

What version of Remix are you using?

No response

Steps to Reproduce

Update data and initialVariantId to a different product and variant.

export default function Product({ data, initialVariantId }) {
  return (
    <ProductProvider data={data} initialVariantId={initialVariantId}>
      <ProductTest />
    </ProductProvider>
  );
}

function ProductTest() {
  const { product, selectedVariant } = useProduct();

  console.log(product.title, selectedVariant.title);

  return (
    <div>
      {product.title} {selectedVariant.title}
    </div>
  );
}

Expected Behavior

Using an apparel store as example I would expect the following behaviour:

  1. Render with "t-shirt" product data and black / XL initialVariantId
  2. console.log outputs T-Shirt Black / XL
  3. Change data prop to "sweatshirt" product data and red / XS initialVariantId
  4. console.log outputs Sweatshirt Red / XS

Actual Behavior

The actual behaviour carries over the selectedOptions to the new product data like this:

  1. Render with "t-shirt" product data and black / XL initialVariantId
  2. console.log outputs T-Shirt Black / XL
  3. Change data prop to "sweatshirt" product data and red / XS initialVariantId
  4. console.log outputs Sweatshirt Black / XL (provided the product has options with the same name and value available)
  5. console.log outputs Sweatshirt Red / XS
@michenly
Copy link
Contributor

michenly commented May 3, 2024

I think this will depends on how you are changing the data and initialVariantId
Can you provide more information about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants