Shopify / shopify-app-bridge

https://shopify.dev/docs/api/app-bridge
86 stars 9 forks source link

Switching resource types causes selection to always be an empty array #201

Open danyn opened 1 year ago

danyn commented 1 year ago

Describe the bug

I have a requirement to allow users to select products or collections.
Two components are used to facilitate this: ResourcePicker resourceType="Product" ResourcePicker resourceType="Collection"

resourceType="Collection" returns an empty array for the payload of onSelection when switching between the ResourcePickers

To Reproduce

Create an app using Shopify cli. create two components where only one is open at a time.

  1. Select a collection using the collection resourceType
  2. Select products using the product resourceType
  3. Select a collection using the collection resourceType
  4. The payload of onSelection often returns an empty array for the collection resource type even when a selection has been made.

Expected behaviour

onSelection is not affected by switching between ResourcePickers of different types. It should always return the selected resources

Contextual information

<ResourcePicker open={state.isChoosingProducts} resourceType="Collection" selectMultiple={false} onSelection={ ({selection}) => { // often this returns any empty selection [] when a ResourcePicker of resourceType="Product" has just been used to select products }}

/>

Packages and versions

"@shopify/app-bridge": "^3.1.0",
"@shopify/app-bridge-react": "^3.1.0",
"@shopify/app-bridge-utils": "^3.1.0",
"@shopify/polaris": "^9.11.0",
"react": "^17.0.2",

Platform

MacBook Pro 2.3 GHz Dual-Core Intel Core i5

Additional context

Built using "shopify-frontend-template-react"