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

Make variant / image updates use useOptimistic and startTransition #1327

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

leerob
Copy link
Member

@leerob leerob commented Apr 19, 2024

CleanShot.2024-04-18.at.19.46.53.mp4

Copy link

vercel bot commented Apr 19, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
commerce-shopify ✅ Ready (Inspect) Visit Preview Apr 19, 2024 2:52am

@@ -21,14 +22,21 @@ export function VariantSelector({
const router = useRouter();
const pathname = usePathname();
const searchParams = useSearchParams();
const [optimisticVariants, setOptimsticVariants] = useOptimistic(variants);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit

Suggested change
const [optimisticVariants, setOptimsticVariants] = useOptimistic(variants);
const [optimisticVariants, setOptimisticVariants] = useOptimistic(variants);


const optionUrl = createUrl(pathname, optimisticOptions);

// Navigate without page reload
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this comment's 100% accurate. It seems that the navigation can't complete without a full page render – at least in the sense that the search params are up-to-date, etc. While the UI is ready to interact with due to the useOptimistic hook, it's still waiting for the full page render before the search params update, so it's now open to race conditions for anything reading from the search params (eg, adding to cart)

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

Successfully merging this pull request may close these issues.

None yet

2 participants