Skip to content

Commit

Permalink
Update variant-selector.tsx (vercel#1115)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens authored Jul 25, 2023
1 parent 586f9bf commit 7dc7e6d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions components/product/variant-selector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import clsx from 'clsx';
import { ProductOption, ProductVariant } from 'lib/shopify/types';
import { createUrl } from 'lib/utils';
import Link from 'next/link';
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
import { redirect, usePathname, useSearchParams } from 'next/navigation';

type ParamsMap = {
[key: string]: string; // ie. { color: 'Red', size: 'Large', ... }
Expand All @@ -26,7 +26,6 @@ export function VariantSelector({
}) {
const pathname = usePathname();
const currentParams = useSearchParams();
const router = useRouter();
const hasNoOptionsOrJustOneOption =
!options.length || (options.length === 1 && options[0]?.values.length === 1);

Expand Down Expand Up @@ -80,7 +79,7 @@ export function VariantSelector({
const selectedVariantUrl = createUrl(pathname, selectedVariantParams);

if (currentUrl !== selectedVariantUrl) {
router.replace(selectedVariantUrl);
redirect(selectedVariantUrl);
}

return options.map((option) => (
Expand Down

0 comments on commit 7dc7e6d

Please sign in to comment.