fix: shipping cost calculation and performance optimization

- Fix shipping cost not included in checkout total
- Add useShippingMethodSelector hook for proper abstraction
- Remove blocking initCheckout from Header for better performance
- Checkout now initializes lazily when cart opens or item added
This commit is contained in:
Unchained
2026-03-30 06:31:52 +02:00
parent adb28c2a91
commit 25e60457cc
3 changed files with 98 additions and 8 deletions

View File

@@ -55,14 +55,14 @@ export default function Header({ locale: propLocale = "sr" }: HeaderProps) {
setLangDropdownOpen(false);
};
// Set language code first, then initialize checkout
// Set language code - checkout initializes lazily when cart is opened
useEffect(() => {
if (locale) {
setLanguageCode(locale);
// Initialize checkout after language code is set
initCheckout();
// Checkout will initialize lazily when user adds to cart or opens cart drawer
// This prevents blocking page render with unnecessary API calls
}
}, [locale, setLanguageCode, initCheckout]);
}, [locale, setLanguageCode]);
useEffect(() => {
const handleScroll = () => {