Skip to content

Commit 0feb6d8

Browse files
authored
Add deprecation warning to renderMode (#4509)
### Background Closes shop/issues-checkout#11640 vault [decision](https://vault.shopify.io/gsd/decisions/10586) Following the introduction of split ship and pickup the `purchase.checkout.pickup-location-option-item.render-after` target is now shared between rendering inline and in a modal. The decision was made to not support modal within modal functionality and to not encourage third party developers to build solutions which utilize this. To be consistent across checkout this thinking should hold true for other targets that render both inline and in a modal: `purchase.checkout.shipping-option-item.render-after` `purchase.checkout.shipping-option-item.details.render` renderMode should be deprecated today and the blocking of modal within modal functionality will occur in the future once the renderMode has been removed ### Solution Add a deprecation warning for renderMode on ShippingOptionItem ### Checklist - [x] I have 🎩'd these changes - [x] I have updated relevant documentation
2 parents b06074d + 7129e7d commit 0feb6d8

5 files changed

Lines changed: 34 additions & 53 deletions

File tree

.changeset/ripe-chairs-cry.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/ui-extensions': patch
3+
---
4+
5+
Deprecate renderMode on shipping option item

packages/ui-extensions/docs/surfaces/checkout/generated/generated_docs_data_v2.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5854,7 +5854,8 @@
58545854
"syntaxKind": "PropertySignature",
58555855
"name": "renderMode",
58565856
"value": "ShippingOptionItemRenderMode",
5857-
"description": "The render mode of this shipping option, indicating how the extension is displayed in the checkout UI."
5857+
"description": "The render mode of this shipping option, indicating how the extension is displayed in the checkout UI.",
5858+
"deprecationMessage": "Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals."
58585859
},
58595860
{
58605861
"filePath": "src/surfaces/checkout/api/shipping/shipping-option-item.ts",
@@ -5864,7 +5865,7 @@
58645865
"description": "The shipping option that this extension is attached to. Use this to read the option's cost, carrier, delivery estimate, and other details.\n\nAvailable only on the corresponding item target. Shipping option item targets expose shipping option properties; pickup location item targets expose pickup location properties."
58655866
}
58665867
],
5867-
"value": "export interface ShippingOptionItemApi {\n /**\n * The shipping option that this extension is attached to. Use this to read the option's cost, carrier, delivery estimate, and other details.\n *\n * Available only on the corresponding item target. Shipping option item\n * targets expose shipping option properties; pickup location item targets\n * expose pickup location properties.\n */\n target: SubscribableSignalLike<ShippingOption>;\n\n /**\n * Whether the buyer has selected the target shipping option. When `true`, the target option is the buyer's active choice. When `false`, the buyer has chosen a different shipping option.\n *\n * Available only on the corresponding item target. Shipping option item\n * targets expose shipping option properties; pickup location item targets\n * expose pickup location properties.\n */\n isTargetSelected: SubscribableSignalLike<boolean>;\n\n /**\n * The render mode of this shipping option, indicating how the extension is displayed in the checkout UI.\n */\n renderMode: ShippingOptionItemRenderMode;\n}"
5868+
"value": "export interface ShippingOptionItemApi {\n /**\n * The shipping option that this extension is attached to. Use this to read the option's cost, carrier, delivery estimate, and other details.\n *\n * Available only on the corresponding item target. Shipping option item\n * targets expose shipping option properties; pickup location item targets\n * expose pickup location properties.\n */\n target: SubscribableSignalLike<ShippingOption>;\n\n /**\n * Whether the buyer has selected the target shipping option. When `true`, the target option is the buyer's active choice. When `false`, the buyer has chosen a different shipping option.\n *\n * Available only on the corresponding item target. Shipping option item\n * targets expose shipping option properties; pickup location item targets\n * expose pickup location properties.\n */\n isTargetSelected: SubscribableSignalLike<boolean>;\n\n /**\n * The render mode of this shipping option, indicating how the extension is displayed in the checkout UI.\n *\n * @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.\n */\n renderMode: ShippingOptionItemRenderMode;\n}"
58685869
}
58695870
},
58705871
"ShippingOptionItemRenderMode": {
@@ -5879,10 +5880,11 @@
58795880
"syntaxKind": "PropertySignature",
58805881
"name": "overlay",
58815882
"value": "boolean",
5882-
"description": "Whether the shipping option is rendered in an overlay. When `true`, the extension appears in a modal or sheet on top of the checkout page. When `false`, the extension renders inline within the shipping options list."
5883+
"description": "Whether the shipping option is rendered in an overlay. When `true`, the extension appears in a modal or sheet on top of the checkout page. When `false`, the extension renders inline within the shipping options list.",
5884+
"deprecationMessage": "Do not rely on render context. Use inline UI instead of opening overlays such as modals."
58835885
}
58845886
],
5885-
"value": "export interface ShippingOptionItemRenderMode {\n /**\n * Whether the shipping option is rendered in an overlay. When `true`, the extension appears in a modal or sheet on top of the checkout page. When `false`, the extension renders inline within the shipping options list.\n */\n overlay: boolean;\n}"
5887+
"value": "export interface ShippingOptionItemRenderMode {\n /**\n * Whether the shipping option is rendered in an overlay. When `true`, the extension appears in a modal or sheet on top of the checkout page. When `false`, the extension renders inline within the shipping options list.\n *\n * @deprecated Do not rely on render context. Use inline UI instead of opening overlays such as modals.\n */\n overlay: boolean;\n}"
58865888
}
58875889
},
58885890
"ShippingOptionListApi": {
@@ -168159,10 +168161,10 @@
168159168161
"returns": {
168160168162
"filePath": "src/surfaces/checkout/preact/shipping-option-target.ts",
168161168163
"description": "",
168162-
"name": "{\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n renderMode: ShippingOptionItemRenderMode;\n}",
168163-
"value": "{\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n renderMode: ShippingOptionItemRenderMode;\n}"
168164+
"name": "{\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n /**\n * @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.\n */\n renderMode: ShippingOptionItemRenderMode;\n}",
168165+
"value": "{\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n /**\n * @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.\n */\n renderMode: ShippingOptionItemRenderMode;\n}"
168164168166
},
168165-
"value": "export function useShippingOptionTarget(): {\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n renderMode: ShippingOptionItemRenderMode;\n} {\n const api = useApi<\n | 'purchase.checkout.shipping-option-item.render-after'\n | 'purchase.checkout.shipping-option-item.details.render'\n >();\n if (!api.target || api.isTargetSelected === undefined) {\n throw new ExtensionHasNoTargetError(\n 'useShippingOptionTarget',\n api.extension.target,\n );\n }\n\n const shippingOptionTarget = useSubscription(api.target);\n const isTargetSelected = useSubscription(api.isTargetSelected);\n const renderMode = api.renderMode;\n\n const shippingOption = useMemo(() => {\n return {\n shippingOptionTarget,\n isTargetSelected,\n renderMode,\n };\n }, [shippingOptionTarget, isTargetSelected, renderMode]);\n\n return shippingOption;\n}"
168167+
"value": "export function useShippingOptionTarget(): {\n shippingOptionTarget: ShippingOption;\n isTargetSelected: boolean;\n /**\n * @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.\n */\n renderMode: ShippingOptionItemRenderMode;\n} {\n const api = useApi<\n | 'purchase.checkout.shipping-option-item.render-after'\n | 'purchase.checkout.shipping-option-item.details.render'\n >();\n if (!api.target || api.isTargetSelected === undefined) {\n throw new ExtensionHasNoTargetError(\n 'useShippingOptionTarget',\n api.extension.target,\n );\n }\n\n const shippingOptionTarget = useSubscription(api.target);\n const isTargetSelected = useSubscription(api.isTargetSelected);\n const renderMode = api.renderMode;\n\n const shippingOption = useMemo(() => {\n return {\n shippingOptionTarget,\n isTargetSelected,\n renderMode,\n };\n }, [shippingOptionTarget, isTargetSelected, renderMode]);\n\n return shippingOption;\n}"
168166168168
}
168167168169
},
168168168170
"UseShopGeneratedType": {
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {render, Fragment} from 'preact';
1+
import {render} from 'preact';
22

33
import {useShippingOptionTarget} from '@shopify/ui-extensions/checkout/preact';
44

@@ -7,56 +7,22 @@ export default function extension() {
77
}
88

99
function Extension() {
10-
const {
11-
shippingOptionTarget,
12-
isTargetSelected,
13-
renderMode,
14-
} = useShippingOptionTarget();
10+
const {shippingOptionTarget, isTargetSelected} =
11+
useShippingOptionTarget();
1512
const {
1613
cost: {amount, currencyCode},
1714
title,
1815
} = shippingOptionTarget;
1916

20-
// When the target is rendered inside the "More shipping options" modal for split shipping scenarios, `renderMode.overlay` is true. This check allows to render an alternative UI to avoid nested modals.
21-
if (renderMode.overlay) {
22-
return (
23-
<s-text>
24-
Shipping method: {title} is{' '}
25-
{isTargetSelected ? '' : 'not'} selected.
26-
</s-text>
27-
);
28-
}
29-
30-
// When the target is rendered inline for both split shipping and non-split shipping scenarios, a Modal can be rendered if desired.
3117
return (
32-
<Fragment>
33-
<s-link
34-
command="--show"
35-
commandFor="my-modal"
36-
>
37-
View details ({title} is{' '}
38-
{isTargetSelected ? '' : 'not'} selected)
39-
</s-link>
40-
<s-modal
41-
id="my-modal"
42-
heading={`Shipping option: ${title}`}
43-
>
44-
<s-paragraph>
45-
Cost:{' '}
46-
{Intl.NumberFormat(undefined, {
47-
style: 'currency',
48-
currency: currencyCode,
49-
}).format(amount)}
50-
</s-paragraph>
51-
<s-button
52-
variant="primary"
53-
command="--hide"
54-
commandFor="my-modal"
55-
slot="primary-action"
56-
>
57-
Close
58-
</s-button>
59-
</s-modal>
60-
</Fragment>
18+
<s-text>
19+
Shipping method: {title} is{' '}
20+
{isTargetSelected ? '' : 'not '}selected.
21+
Cost:{' '}
22+
{Intl.NumberFormat(undefined, {
23+
style: 'currency',
24+
currency: currencyCode,
25+
}).format(amount)}
26+
</s-text>
6127
);
6228
}

packages/ui-extensions/src/surfaces/checkout/api/shipping/shipping-option-item.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,22 @@ export interface ShippingOptionItemApi {
2323

2424
/**
2525
* The render mode of this shipping option, indicating how the extension is displayed in the checkout UI.
26+
*
27+
* @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.
2628
*/
2729
renderMode: ShippingOptionItemRenderMode;
2830
}
2931

3032
/**
3133
* The render mode of a shipping option.
34+
*
3235
* @publicDocs
3336
*/
3437
export interface ShippingOptionItemRenderMode {
3538
/**
3639
* Whether the shipping option is rendered in an overlay. When `true`, the extension appears in a modal or sheet on top of the checkout page. When `false`, the extension renders inline within the shipping options list.
40+
*
41+
* @deprecated Do not rely on render context. Use inline UI instead of opening overlays such as modals.
3742
*/
3843
overlay: boolean;
3944
}

packages/ui-extensions/src/surfaces/checkout/preact/shipping-option-target.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import {useSubscription} from './subscription';
1717
export function useShippingOptionTarget(): {
1818
shippingOptionTarget: ShippingOption;
1919
isTargetSelected: boolean;
20+
/**
21+
* @deprecated Do not rely on render context. This target can render inside an overlay, so use inline UI instead of opening overlays such as modals.
22+
*/
2023
renderMode: ShippingOptionItemRenderMode;
2124
} {
2225
const api = useApi<

0 commit comments

Comments
 (0)