Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Keep the delivery method sheet out of browser history (#14423)

Damian Legawiec54e5e4cec663
diff --git a/packages/dashboard/e2e/delivery-settings.spec.ts b/packages/dashboard/e2e/delivery-settings.spec.ts
index 5a1785bc61..6b38f4c42d 100644
--- a/packages/dashboard/e2e/delivery-settings.spec.ts
+++ b/packages/dashboard/e2e/delivery-settings.spec.ts
@@ -112,6 +112,11 @@ test.describe('delivery profiles', () => {
await page.getByRole('button', { name: /^cancel$/i }).click()
await expect(page.getByRole('heading', { name: /new delivery method/i })).toHaveCount(0)
await expect(page.getByRole('heading', { name: profileName })).toBeVisible()
+
+ // The sheet replaces its history entry rather than pushing one, so going
+ // back does not reopen what the merchant just dismissed.
+ await page.goBack()
+ await expect(page.getByRole('heading', { name: /new delivery method/i })).toHaveCount(0)
})
// Pickup is a separate card because it has no destination: the merchant
@@ -179,6 +184,11 @@ test.describe('delivery profiles', () => {
timeout: 15_000,
})
await expect(page.getByText(methodName)).toBeVisible({ timeout: 15_000 })
+
+ // Opening and closing the sheet must not leave the header's back arrow
+ // walking through dismissed sheets — it goes to the profile list.
+ await page.getByRole('button', { name: /^back$/i }).click()
+ await expect(page.getByRole('button', { name: PROFILE_CTA })).toBeVisible({ timeout: 15_000 })
})
// The origin-group layer stays invisible until a profile is split, so this
diff --git a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index.tsx b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index.tsx
index 930840f583..a1516cd0dd 100644
--- a/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index.tsx
+++ b/packages/dashboard/src/routes/_authenticated/$storeId/settings/delivery-profiles/$profileId/index.tsx
@@ -106,12 +106,21 @@ export const Route = createFileRoute(
component: DeliveryProfileDetailPage,
})
-/** Opens the method sheet for an existing method, or for a new one. */
+/**
+ * Opens the method sheet for an existing method, or for a new one.
+ *
+ * Every move replaces the history entry rather than pushing one. The sheet
+ * lives in the URL so a deep link reopens it, but opening and closing one is
+ * not a place a merchant navigated to — pushing would leave the page's back
+ * arrow walking through sheets they already dismissed instead of returning to
+ * the profile list.
+ */
function useMethodSheetNavigation() {
const navigate = useNavigate()
const openMethod = (methodId: string) =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { zone: _z, group: _g, provider: _p, ...rest } = prev
return { ...rest, method: methodId } as never
@@ -120,6 +129,7 @@ function useMethodSheetNavigation() {
const openNewMethod = (options: { zone?: string; group?: string; provider?: string } = {}) =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) =>
({
...prev,
@@ -132,6 +142,7 @@ function useMethodSheetNavigation() {
const closeMethodSheet = () =>
navigate({
+ replace: true,
search: (prev: Record<string, unknown>) => {
const { method: _m, zone: _z, group: _g, provider: _p, ...rest } = prev
return rest as never