diff --git a/.changeset/late-cats-jump.md b/.changeset/late-cats-jump.md
new file mode 100644
index 0000000000..77817f3594
--- /dev/null
+++ b/.changeset/late-cats-jump.md
@@ -0,0 +1,5 @@
+---
+'@graphcommerce/ecommerce-ui': patch
+---
+
+`` will default to loading, restoring the previous behavior. This might introduce , this might introduce an additional spinner but prevents a flash where it is shown that there is no cart
diff --git a/.changeset/mighty-humans-listen.md b/.changeset/mighty-humans-listen.md
new file mode 100644
index 0000000000..5fce194f9a
--- /dev/null
+++ b/.changeset/mighty-humans-listen.md
@@ -0,0 +1,7 @@
+---
+'@graphcommerce/magento-cart-shipping-address': patch
+'@graphcommerce/magento-newsletter': patch
+'@graphcommerce/magento-cart': patch
+---
+
+Deprecate the allowUrl option for useCartQuery, it was already enabled by default and should never be set to false.
diff --git a/.changeset/nice-bugs-push.md b/.changeset/nice-bugs-push.md
new file mode 100644
index 0000000000..8f7c1aebdd
--- /dev/null
+++ b/.changeset/nice-bugs-push.md
@@ -0,0 +1,6 @@
+---
+"@graphcommerce/magento-cart": patch
+"@graphcommerce/magento-customer": patch
+---
+
+Solve an issue where the user would be presented with the Session expired dialog when the user would be logging in during the checkout process.
diff --git a/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx b/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx
index 4f52af378b..247778db2d 100644
--- a/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx
+++ b/packages/ecommerce-ui/components/WaitForQueries/WaitForQueries.tsx
@@ -1,3 +1,4 @@
+import { useIsomorphicLayoutEffect } from '@graphcommerce/framer-utils'
import { QueryResult } from '@graphcommerce/graphql'
import React, { startTransition, useEffect, useState } from 'react'
@@ -10,13 +11,13 @@ export type WaitForQueriesProps = {
/** Shows the fallback during: SSR, Hydration and Query Loading. */
export const WaitForQueries = (props: WaitForQueriesProps) => {
- const { waitFor, fallback, children, noSsr = false } = props
+ const { waitFor, fallback, children, noSsr = true } = props
// Make sure the first render is always the same as the server.
// Make sure we we use startTransition to make sure we don't get into trouble with Suspense.
const [mounted, setMounted] = useState(!noSsr)
useEffect(() => {
- if (noSsr) startTransition(() => setMounted(true))
+ if (noSsr) setMounted(true)
}, [noSsr])
// We are done when all queries either have data or an error.
diff --git a/packages/magento-cart-payment-method/hooks/useCartLock.ts b/packages/magento-cart-payment-method/hooks/useCartLock.ts
index d687ce145f..38e666644f 100644
--- a/packages/magento-cart-payment-method/hooks/useCartLock.ts
+++ b/packages/magento-cart-payment-method/hooks/useCartLock.ts
@@ -1,4 +1,5 @@
-import { useCurrentCartId } from '@graphcommerce/magento-cart'
+import { useApolloClient } from '@graphcommerce/graphql'
+import { cartLock, useCurrentCartId } from '@graphcommerce/magento-cart'
import { useUrlQuery } from '@graphcommerce/next-ui'
import { useEffect, useState } from 'react'
@@ -19,9 +20,10 @@ let justLocked = false
* Todo: Block all operations on the cart while the cart is being blocked.
*/
export function useCartLock() {
- const { currentCartId } = useCurrentCartId()
+ const { currentCartId, locked } = useCurrentCartId()
const [queryState, setRouterQuery] = useUrlQuery()
const [, setForceRender] = useState(0)
+ const client = useApolloClient()
useEffect(() => {
const pageshow = (e: PageTransitionEvent) => {
@@ -38,6 +40,7 @@ export function useCartLock() {
const lock = (params: Omit) => {
if (!currentCartId) return undefined
justLocked = true
+ cartLock(client.cache, true)
return setRouterQuery({
locked: '1',
cart_id: currentCartId,
@@ -46,13 +49,14 @@ export function useCartLock() {
}
const unlock = async (params: Omit) => {
+ cartLock(client.cache, false)
await setRouterQuery({ cart_id: null, locked: null, method: null, ...params } as E)
return queryState
}
const resulting: Omit & { locked: boolean; justLocked: boolean } = {
...queryState,
- locked: queryState.locked === '1' || Boolean(queryState.PayerID),
+ locked: locked || queryState.locked === '1' || Boolean(queryState.PayerID),
justLocked,
}
diff --git a/packages/magento-cart/components/CartDebugger/CartDebugger.tsx b/packages/magento-cart/components/CartDebugger/CartDebugger.tsx
index 05152c3fb8..21f066e123 100644
--- a/packages/magento-cart/components/CartDebugger/CartDebugger.tsx
+++ b/packages/magento-cart/components/CartDebugger/CartDebugger.tsx
@@ -1,6 +1,6 @@
import { useApolloClient } from '@graphcommerce/graphql'
import { Button } from '@mui/material'
-import { CurrentCartIdDocument } from '../../hooks/CurrentCartId.gql'
+import { readCartId, writeCartId } from '../../hooks'
export function CartDebugger() {
const client = useApolloClient()
@@ -12,24 +12,14 @@ export function CartDebugger() {
variant='text'
size='small'
onClick={() => {
- const currentCardId = client.readQuery({ query: CurrentCartIdDocument })
- if (!currentCardId?.currentCartId) {
+ const currentCartId = readCartId(client.cache)
+ if (!currentCartId) {
// eslint-disable-next-line no-console
console.log('No customerToken available, nothing to break')
} else {
// eslint-disable-next-line no-console
console.log(`Changing current token to a random one`)
-
- client.writeQuery({
- query: CurrentCartIdDocument,
- data: {
- currentCartId: {
- ...currentCardId.currentCartId,
- id: `${Math.random().toString(36).slice(2)}random-cardId`,
- },
- },
- broadcast: true,
- })
+ writeCartId(client.cache, `${Math.random().toString(36).slice(2)}random-cardId`)
}
}}
>
diff --git a/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx b/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx
index 82971603cb..4aa6e5c1af 100644
--- a/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx
+++ b/packages/magento-cart/components/CartItemSummary/CartItemSummary.tsx
@@ -38,10 +38,7 @@ type OrderSummaryProps = ActionCardLayoutProps & {
export function CartItemSummary(props: OrderSummaryProps) {
const { sx = [], size, layout = 'list', itemProps, ...cardLayout } = props
- const { data } = useCartQuery(CartItemSummaryDocument, {
- allowUrl: true,
- fetchPolicy: 'cache-only',
- })
+ const { data } = useCartQuery(CartItemSummaryDocument, { fetchPolicy: 'cache-only' })
if (!data?.cart) return null
@@ -85,7 +82,7 @@ export function CartItemSummary(props: OrderSummaryProps) {
className={classes.scrollerContainer}
{...cardLayout}
>
- {items?.filter(nonNullable).map((item) => (
+ {(items ?? []).filter(nonNullable).map((item) => (
* @see https://github.com/magento/magento2/issues/33848
*/
export function CartTotals(props: CartTotalsProps) {
- const { data } = useCartQuery(GetCartTotalsDocument, { allowUrl: true })
+ const { data } = useCartQuery(GetCartTotalsDocument)
const { containerMargin, additionalSubtotals, additionalTotals, sx = [] } = props
const classes = withState({ containerMargin })
diff --git a/packages/magento-cart/hooks/CurrentCartId.graphql b/packages/magento-cart/hooks/CurrentCartId.graphql
index 0ed32d02f5..a8b4b8a3bf 100644
--- a/packages/magento-cart/hooks/CurrentCartId.graphql
+++ b/packages/magento-cart/hooks/CurrentCartId.graphql
@@ -2,5 +2,6 @@ query CurrentCartId {
currentCartId @client {
__typename
id
+ locked
}
}
diff --git a/packages/magento-cart/hooks/CurrentCartId.graphqls b/packages/magento-cart/hooks/CurrentCartId.graphqls
index e9cee2a29c..4856711677 100644
--- a/packages/magento-cart/hooks/CurrentCartId.graphqls
+++ b/packages/magento-cart/hooks/CurrentCartId.graphqls
@@ -4,6 +4,7 @@ extend type Query {
type CurrentCartId {
id: String
+ locked: Boolean
}
input RegisterCartIdInput {
diff --git a/packages/magento-cart/hooks/CustomerCart.graphql b/packages/magento-cart/hooks/CustomerCart.graphql
index 3ce034a4e3..d055551c10 100644
--- a/packages/magento-cart/hooks/CustomerCart.graphql
+++ b/packages/magento-cart/hooks/CustomerCart.graphql
@@ -2,6 +2,5 @@ query CustomerCart {
customerCart {
id
__typename
- ...CartItemCountChanged
}
}
diff --git a/packages/magento-cart/hooks/UseMergeCustomerCart.graphql b/packages/magento-cart/hooks/MergeCarts.graphql
similarity index 50%
rename from packages/magento-cart/hooks/UseMergeCustomerCart.graphql
rename to packages/magento-cart/hooks/MergeCarts.graphql
index 2ffb7fc8ad..9bb7d501e6 100644
--- a/packages/magento-cart/hooks/UseMergeCustomerCart.graphql
+++ b/packages/magento-cart/hooks/MergeCarts.graphql
@@ -1,7 +1,6 @@
-mutation UseMergeCustomerCart($sourceCartId: String!, $destinationCartId: String!) {
+mutation MergeCarts($sourceCartId: String!, $destinationCartId: String!) {
mergeCarts(source_cart_id: $sourceCartId, destination_cart_id: $destinationCartId) {
__typename
id
- ...CartItemCountChanged
}
}
diff --git a/packages/magento-cart/hooks/useAssignCurrentCartId.ts b/packages/magento-cart/hooks/useAssignCurrentCartId.ts
index de62813bec..dfc3fb1213 100644
--- a/packages/magento-cart/hooks/useAssignCurrentCartId.ts
+++ b/packages/magento-cart/hooks/useAssignCurrentCartId.ts
@@ -8,11 +8,26 @@ export const CART_ID_COOKIE = 'cart'
export function writeCartId(cache: ApolloCache